1

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

1 Answer 1

2

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.

1
  • Read about running remote commands in Windows PowerShell by entering command Get-Help about_Remote_Requirements
    – Aynyuh
    Jul 24, 2015 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .