标签:powershell 安装程序 注册表
有的时候,豆子使用GPO安装软件之后,希望查看在客户端是否成功安装,Windows客户端可能有几百上千台,于是豆子写了个简单的程序来进行查看。
思路如下:
传递参数软件名字和操作系统名字,搜索到对应的计算机对象,对于每一个对象创建远程session,如果失败(比如关机或者其他情况),输出失败计算机的名字;对于成功连接的对象,根据32bit或者64bit查询注册表,输出结果。
function Get-Software{ [cmdletbinding()] param( [parameter(mandatory=$true,position=1)][string]$software, [ValidateSet("2008", "2012", "2003","7","8","10")][string]$OS ) Write-verbose "Scanning Computers.." $a=Get-ADComputer -Filter "operatingsystem -like ‘*$OS*‘ " -Properties operatingsystem,ipv4address | Where-Object{$_.ipv4address -ne $null} | select -ExpandProperty name #$a=Get-ADComputer -Filter "operatingsystem -like ‘*$OS*‘ " -Properties operatingsystem,ipv4address | Where-Object{Test-Connection -ComputerName $_.name -Count 1-quiet} | select -ExpandProperty name Write-verbose "Initialising New Sessions.." $session=New-PSSession -ComputerName $a -ErrorAction SilentlyContinue -ErrorVariable err if($err -ne $null){ Write-Warning "Following mahcines cannot setup a session" $err.targetobject } $scriptblock={ param([string]$name) if ([System.IntPtr]::Size -eq 4) { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object{$_.displayname -like "*$name*"} | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate } else { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*,HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object{$_.displayname -like "*$name*"} | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate } } Write-Verbose "Generating Reports" $s=invoke-command -Session $session $scriptblock -ArgumentList $software $s | Out-GridView } Get-software -software "silverlight" -OS 7 -Verbose
结果如下
本文出自 “麻婆豆腐” 博客,请务必保留此出处http://beanxyz.blog.51cto.com/5570417/1695998
标签:powershell 安装程序 注册表
原文地址:http://beanxyz.blog.51cto.com/5570417/1695998