For some scripts, i need to have an output composed of calculated properties.
For example, for a list of ip addresses in ip.txt, i want to know if they respond to ping. So i try the following command:
Get-Content .\ip.txt | Select-Object $_,@{Name="ping?";Expression={Test-Connection $_ -Quiet -Count 1}}
But i get an error, regardless of what i do in the scriptblock expression.
The error (in french, sorry):
Select-Object : Paramètre Null. Le type attendu doit être l'un des suivants : {System.String, System.Management.Automation.ScriptBlock}.
Au niveau de ligne : 1 Caractère : 37
+ Get-Content .\ip.txt | Select-Object <<<< $_,@{Name="ping?";Expression={Test-Connection $_ -Quiet -Count 1}}
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
I used the "calculated properties" in some scripts before, but with directories objects. Why it doesnt work with strings?