为什么会提示InputObjectNotBound,Get-FileHash,请问什么意思?


PowerShell交流中心分类: Powershell基础为什么会提示InputObjectNotBound,Get-FileHash,请问什么意思?
0
get-f asked 7年 ago

powershell执行
Get-ChildItem e:\ -Filter *.jpg -Recurse |
Get-FileHash -Algorithm SHA1
这个是正常的,get-filehash正确的执行了get-childitem的输出
为什么在执行
Get-Clipboard |
Get-FileHash -Algorithm SHA1
这个的时候提示input object not bound?

1 Answers
1
Best Answer
Mooser Lee 管理员 answered 7年 ago

Get-FileHash [-Path] <string[]> 
中有一个参数:-LiteralPath <string[]>
Required? true
Position? Named
Accept pipeline input? true (ByPropertyName)
Parameter set name LiteralPath
Aliases PSPath
Dynamic? false
是可以自动从管道中元素的属性中读取的,Get-ChildItem正好有,但是Get-Clipboard没有。
所以遇到这样情况,应当自己手动指定参数:
 

PS> dir -File | select -First 5 -ExpandProperty fullname | clip.exe
PS> Get-Clipboard
D:\Users\mosser\.bash_history
D:\Users\mosser\.gitconfig
D:\Users\mosser\1.bat
D:\Users\mosser\a.csv
D:\Users\mosser\a.ps1

PS> Get-Clipboard | foreach {Get-FileHash -LiteralPath $_}

Algorithm Hash Path
--------- ---- ----
SHA256 9577A8BFED904BD55390BA203F1A233BE1981B36FA945537EB3BE5B2446DE031 D:\Users\mosser\.bash_history
SHA256 416B992DD5A5C46E9D646784A2B4A019108A863096D884FA012F2E5BD9AF3621 D:\Users\mosser\.gitconfig
SHA256 965C079BB84A56FB67F247D5009A4475D183DA8A10950F555CF05234928BE9B4 D:\Users\mosser\1.bat
SHA256 4A5C428653C29FC5AD9D4D82A459FD9B32F716EE2E02A2C0F6968FD46AFDE580 D:\Users\mosser\a.csv
SHA256 C66324D6EB25344B1681544123F275BFAD3DB73CE851E0CF59D1B1E54615B105 D:\Users\mosser\a.ps1
get-f replied 7年 ago

谢谢您的解惑。