45 lines
1.7 KiB
PowerShell
45 lines
1.7 KiB
PowerShell
$allComputers=Get-Content -Path C:\temp\pctest.txt
|
|
foreach($computer in $allComputers)
|
|
{
|
|
|
|
$isonline=test-connection -Quiet -count 2 -ComputerName $computer
|
|
if($isonline)
|
|
{
|
|
Write-Host -ForegroundColor Green "$computer is online";
|
|
|
|
$output=@()
|
|
$remotereg=0
|
|
if ($service=Invoke-Command -ComputerName $computer -ScriptBlock {Get-Service -Name RemoteRegistry}
|
|
{
|
|
Get-Service -ComputerName $computer -Name RemoteRegistry | Start-Service
|
|
$remotereg=1
|
|
Write-Host -ForegroundColor Green "$computer remote registry started";
|
|
}
|
|
$InstalledSoftwareKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
|
|
$InstalledSoftware=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine', $computer)
|
|
$RegistryKey=$InstalledSoftware.OpenSubKey($InstalledSoftwareKey)
|
|
$SubKeys=$RegistryKey.GetSubKeyNames()
|
|
Foreach ($key in $SubKeys){
|
|
$thisKey=$InstalledSoftwareKey+"\\"+$key
|
|
$thisSubKey=$InstalledSoftware.OpenSubKey($thisKey)
|
|
$obj = New-Object PSObject
|
|
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computer
|
|
$obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
|
|
$obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
|
|
$obj | Add-Member -MemberType NoteProperty -Name "InstallDate" -Value $($thisSubKey.GetValue("InstallDate"))
|
|
$output += $obj
|
|
}
|
|
$output | where { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, InstallDate | FT
|
|
$output=@()
|
|
if ($remotereg=1)
|
|
{
|
|
Get-Service -ComputerName $computer -Name RemoteRegistry | Stop-Service
|
|
Write-Host -ForegroundColor Green "$computer remote registry stopped";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Write-Host -ForegroundColor Red "`n$computer is offline `n";
|
|
}
|
|
|
|
} |