与 Powershell 的 |sh 相当?

Comparable |sh for Powershell?

我有一个系统,很多人都在登录并获取临时配置文件。所以,我想在注册表中查询“.bak”配置文件,然后查询 C:\Users 文件夹的结果,这样我就可以确定他们的文件夹是否存在。

到目前为止,我有这个:

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" | findstr /i ".bak" | %{$_ -replace "^","reg query """} |%{$_ -replace "$",""" | findstr ProfileImagePath >> d:\temp\Results.dat"}

这会产生如下命令:

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-9876543238-1234562203-7654325021-1001" | findstr ProfileImagePath >> d:\temp\Results.dat
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-1234563238-1234562203-7654325021-1003" | findstr ProfileImagePath >> d:\temp\Results.dat

在 Unix/Linux 世界中,使用 SED,我可以将其通过管道传输到 运行 ( | sh )。 是否有类似的 Powershell 调用,我可以在其中将重新格式化的命令通过管道传输到现在 运行?

我会做这样的事情。将键名通过管道传递给 get-item属性,然后使用 select-object.

选择 profileimagepath 属性
get-item 'HKLM:\software\Microsoft\Windows NT\CurrentVersion\ProfileList\*.bak' | 
  get-itemproperty -Name ProfileImagePath | 
  select-object ProfileImagePath


ProfileImagePath
----------------
c:\users\fake
c:\users\fake2

下面是使用测试路径的方法:

get-item 'HKLM:\software\Microsoft\Windows NT\CurrentVersion\ProfileList\*.bak' |
  get-itemproperty |
  select-object ProfileImagePath, @{name='Exists'; 
  expression={test-path $_.ProfileImagePath}}


ProfileImagePath Exists
---------------- ------
c:\users\fake      True
c:\users\fake2    False