1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| 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
|