小编Aru*_*run的帖子

变量中的 Powershell 搜索字符串(不是文本文件)

我试图从存储“systeminfo”命令输出但遇到问题的变量“$a”中搜索名为“Hostname”的字符串。我正在使用“系统信息”来收集更大的数据集。

代码:

$a= (get-systeminfo -computername localhost | select-object hostname, OSNAME, osversion, model, type)  
write-output $a 
select-string $a -pattern "hostname"
Run Code Online (Sandbox Code Playgroud)

错误:

Select-String : Cannot find path 'C:\Users\john001c\@{Hostname=PACCPL-FTN1TM1; OSName=Microsoft Windows 7 Enterprise ; OSVersion=6.1.7601 Service Pack 1 Build 7601; Model=Latitude E
4310; Type=x64-based PC}' because it does not exist.

At line:5 char:14
+ select-string <<<<  $a -pattern "hostname"
    + CategoryInfo          : ObjectNotFound: (C:\Users\john...e=x64-based PC}:String) [Select-String], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SelectStringCommand
Run Code Online (Sandbox Code Playgroud)

在变量中搜索字符串的正确方法是什么?

windows powershell

5
推荐指数
1
解决办法
6万
查看次数

标签 统计

powershell ×1

windows ×1