$Software=@{}
Import-CSV ".\computers.csv" -header("ComputerName") | ForEach {
$array = @()
$computername = $_.ComputerName #чуть-чуть упростим, мне так удобнее :)
#Define the variable to hold the location of Currently Installed Programs
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
#Create an instance of the Registry Object and open the HKLM base key
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computername)
#Drill down into the Uninstall key using the OpenSubKey Method
$regkey=$reg.OpenSubKey($UninstallKey)
#Retrieve an array of string that contain all the subkey names
$subkeys=$regkey.GetSubKeyNames()
#Open each Subkey and use GetValue Method to return the required values for each
foreach($key in $subkeys){
$thisKey=$UninstallKey+"\\"+$key
$thisSubKey=$reg.OpenSubKey($thisKey)
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
$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 "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
$obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
$array += $obj
}
$Software.Add($computername,$array)
}
foreach ($pc in $Software.Keys ) {
write-host "Save" $pc
$Software[$pc] | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto >> c:\temp\$pc.txt
}
echo %DATE%
Import-CSV ".\computers.csv" -header("ComputerName") | ForEach {
$ComputerName = $_.ComputerName
New-Item \\$ComputerName\c$\temp -Type Directory
Copy-Item "script.cmd" \\$ComputerName\c$\temp\
.\psexec.exe \\$ComputerName "C:\temp\script.cmd"
}
sam-01
sam-02
sam-03
sam-04
sam-05
sam-06
PS E:\work\rn\Zabbix\ManageAgents> .\test.ps1
PsExec v2.0 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
C:\WINDOWS\system32>echo 22.07.2016
22.07.2016
C:\temp\script.cmd exited on sam-01 with error code 0.
Get-WmiObject -computername -class win32_product | ft name,vendor,version,caption