生活随笔
收集整理的這篇文章主要介紹了
Powershell 查看软件是否成功安装
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
有的時(shí)候,豆子使用GPO安裝軟件之后,希望查看在客戶端是否成功安裝,Windows客戶端可能有幾百上千臺(tái),于是豆子寫了個(gè)簡(jiǎn)單的程序來進(jìn)行查看。
思路如下:
傳遞參數(shù)軟件名字和操作系統(tǒng)名字,搜索到對(duì)應(yīng)的計(jì)算機(jī)對(duì)象,對(duì)于每一個(gè)對(duì)象創(chuàng)建遠(yuǎn)程session,如果失敗(比如關(guān)機(jī)或者其他情況),輸出失敗計(jì)算機(jī)的名字;對(duì)于成功連接的對(duì)象,根據(jù)32bit或者64bit查詢注冊(cè)表,輸出結(jié)果。如果該軟件不存在,返回n/a的一個(gè)自定義的對(duì)象
#查詢域內(nèi)的軟件安裝情況function?Get-Software{<#.SYNOPSISFunction?that?allows?you?to?Query?Software?in?AD?domain.DESCRIPTIONYou?can?add?the?function?to?your?scripts,?dot?source?it?to?load?into?your?currentPowerShell?session?or?add?it?to?your?$Profile?so?it?is?always?available.To?dot?source:.".\Get-Software.ps1".PARAMETER?PropertyProperty,?or?column?that?you?will?be?keying?on.??.PARAMETER?softwareThe?software?name?you?want?to?search.PARAMETER?osoperating?system?name,?you?don't?need?to?input?the?full?name,?any?keyword?will?work.PARAMETER?dnSpecifies?the?searchbase?of?your?AD?query.EXAMPLEGet-Software?-software?globalprotect?-DN?"ou=aaa?Group?Workstations,ou=aaa?Group?Machines,?dc=aaa,dc=com,dc=au"??-os?7Assume?check?PaloAlto?***?agent?installation?status?for?all?windows?7?machines?in?a?designated?OU.EXAMPLEGet-Software?-software?silver?|?export-csv?c:\temp\result.csvGet?the?SilverLight?Installation?status?in?the?domain?and?export?to?a?csv?file?.NOTESAuthor:?????????????Yuan?LiQQ:?????????????????38144205Blog:???????????????beanxyz.blog.51cto.com#>[cmdletbinding()]param([parameter(mandatory=$true,position=1)][string]$software,[string]$OS='',#當(dāng)前域的DN,根據(jù)自己情況修改[string]$DN='dc=aaa,dc=com,dc=au')Write-Verbose?"Scanning?Computers..."if($os?-ne?''){$a=Get-ADComputer?-filter?"operatingsystem?-like?'*$os*'?"?-Searchbase?"$dn"?-Properties?operatingsystem,ipv4address??|?Where-Object{$_.ipv4address?-ne?$null}?|?select?-ExpandProperty?name}else{$a=Get-ADComputer?-Filter?*??-Searchbase?"$dn"?-Properties?operatingsystem,ipv4address??|?Where-Object{$_.ipv4address?-ne?$null}?|?select?-ExpandProperty?name}Write-Verbose?"Scanning?Software?..."$s=Invoke-Command?-ComputerName?$a?-erroraction?SilentlyContinue?-ErrorVariable?disconnect{param([string]$name)#如果是64位系統(tǒng)if?([System.IntPtr]::Size?-eq?4)?{$result=Get-ItemProperty?HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*?|?Where-Object{$_.displayname?-like?"*$name*"}?|?Select-Object?DisplayName,?DisplayVersion,?Publisher,?InstallDate,?@{n='OS';e={(Get-WmiObject?Win32_OperatingSystem).name.split("|")[0]}}?#如果沒有找到那么返回值為N/A的一個(gè)空的對(duì)象if?($result?-eq?$null){$info?=?""?|?select?Displayname,DisplayVersion,?Publisher,?InstallDate,?OS$info.Displayname?=?'N/A'$info.DisplayVersion='N/A'$info.Publisher='N/A'$info.InstallDate='N/A'$info.OS=Get-WmiObject?-Class?win32_operatingsystem?|?select?-expand?caption$info}?else{$result}}?#如果是32位系統(tǒng)else?{?$result=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,@{n='OS';e={(Get-WmiObject?Win32_OperatingSystem).name.split("|")[0]}}?if?($result?-eq?$null){$info?=?""?|?select?Displayname,DisplayVersion,?Publisher,?InstallDate,?OS$info.Displayname?=?'N/A'$info.DisplayVersion='N/A'$info.Publisher='N/A'$info.InstallDate='N/A'$info.OS=Get-WmiObject?-Class?win32_operatingsystem?|?select?-expand?caption$info}?else{$result}}}?-ArgumentList?$softwareif($disconnect.taregetobject?-eq?"*"){Write-host?"Disconnected?Computers"?-ForegroundColor?red$disconnect.targetobject}return?$s}Get-Software?-software?globalprotect?-DN?"ou=DDB?Group?Workstations,ou=DDB?Group?Machines,?dc=omnicom,dc=com,dc=au"??|?Out-GridView
結(jié)果如下
總結(jié)
以上是生活随笔為你收集整理的Powershell 查看软件是否成功安装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。