获取内容问题

时间:2011-08-31 12:07:48

标签: powershell

基本的PowerShell问题 - 我在c:\ temp \ servers.txt文件中有两台计算机,想要查询tcpip.sys文件版本信息。我继续收到错误,但似乎也有效......

  

PS C:\ Windows \ System32 \ drivers> Get-Content C:\ temp \ servers.txt |   ForEach-Object(Get-ChildItem c:\ windows \ system32 \ drivers \ tcpip.sys).Versioninfo

我收到以下错误:

  

ForEach-Object:>无法绑定参数'Process'。无法转换“文件:
  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驱动程序产品:
  Microsoftr Windowsr操作系统ProductVersion:6.1.7600.16385   Debug:False Patched:False PreRelease:
  False PrivateBuild:False SpecialBuild:False语言:
  英语(美国)“类型的价值   键入“System.Diagnostics.FileVersionInfo”   “System.Management.Automation.ScriptBlock”。在线:1字符: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

1 个答案:

答案 0 :(得分:4)

您需要为每个服务器构建一个UNC路径:

Get-Content C:\temp\servers.txt | ForEach-Object {
    (Get-ChildItem \\$_\c$\windows\system32\drivers\tcpip.sys).Versioninfo 
}

您还需要使用大括号,而不是括号,这就是错误的原因。

相关问题