Basic powershell question here - I have two computers in the c:\temp\servers.txt file and want to query the tcpip.sys file version info. I keep on getting an error but it also seems to work....
PS C:\Windows\System32\drivers> Get-Content C:\temp\servers.txt | ForEach-Object (Get-ChildItem c:\windows\system32\drivers\tcpip.sys).Versioninfo
I get the below error:
ForEach-Object :> Cannot bind parameter 'Process'. Cannot convert the "File:
C:\windows\system32\drivers\tcpip.sys InternalName: tcpip.sys OriginalFilename: tcpip.sys.mui FileVersion: 6.1.7600.16385 (win7_rtm.090713-1255) FileDescription: TCP/IP Driv开发者_JAVA技巧er Product: Microsoftr Windowsr Operating System ProductVersion: 6.1.7600.16385 Debug: False Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language: English (United States) " value of type "System.Diagnostics.FileVersionInfo" to type "System.Management.Automation.ScriptBlock". At line:1 char:49 + Get-Content C:\temp\servers.txt | ForEach-Object <<<< (Get-ChildItem c:\windows\system32\drivers\tcpip.sys).Versioninfo + CategoryInfo : InvalidArgument: (:) [ForEach-Object], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand
You need to construct a UNC path to each each server:
Get-Content C:\temp\servers.txt | ForEach-Object {
(Get-ChildItem \\$_\c$\windows\system32\drivers\tcpip.sys).Versioninfo
}
You also need to use braces, not parenthesis, that's why you the error.
精彩评论