Powershell script get .NET Framework versions from remote PCs

6,238

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.

Share:
6,238

Related videos on Youtube

Darius S
Author by

Darius S

Updated on September 18, 2022

Comments

  • Darius S
    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
    Aynyuh almost 9 years
    Read about running remote commands in Windows PowerShell by entering command Get-Help about_Remote_Requirements