Powershell script get .NET Framework versions from remote PCs
Get-ChildItem waits path from pipeline, not a computer name. First thing that you need is get computer object with it's attributes (name, type, description) from CSV file:
Get-Content -Path "c:\temp\servers.csv" | ConvertFrom-Csv | ForEach-Object -Process {
Write-Host "Server name: " -NoNewline
Write-Host $_.Name
}
Next you need to execute commands remotely with Invoke-Command:
Invoke-Command -ComputerName $_.Name -ScriptBlock {
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP'
}
Finally:
Get-Content -Path "c:\temp\servers.csv" | ConvertFrom-Csv | ForEach-Object -Process {
Invoke-Command -ComputerName $_.Name -ScriptBlock {
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP'
}
}
To run script block with specified credentials use parameter -Credential in Invoke-Command.
Related videos on Youtube
![Darius S](https://lh6.googleusercontent.com/-hb40s4ELSmU/AAAAAAAAAAI/AAAAAAAAA30/onVRcqiNIB4/photo.jpg?sz=256)
Darius S
Updated on September 18, 2022Comments
-
Darius S almost 2 years
I have the following script.
Get-Content comps.csv | Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | Get-ItemProperty -name Version,Release -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version, Release
My comps.csv content
Name,Type,Description, ALYTAUS-PC,Computer,, AUGUSTE-PC,Computer,, AUSRA-PC,Computer,, BIRZU-PC,Computer,, VYTAUTO-PC1,Computer,,
I got that message for each object in csv:Get-ChildItem : The input object cannot be bound to any parameters for the command either because the command does n ot take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:38 + Get-Content comps.csv | Get-ChildItem <<<< 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | + CategoryInfo : InvalidArgument: (VYTAUTO-PC1,Computer,,:PSObject) [Get-ChildItem], ParameterBindingE xception + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.GetChildItemCommand
-
Aynyuh almost 9 yearsRead about running remote commands in Windows PowerShell by entering command
Get-Help about_Remote_Requirements