2014-05-01 38 views
1

如何在一行上在PowerShell中執行多個命令?在PowerShell中執行多個cmdlet

我試圖解開該目錄中的文件和輸出他們的名字:

@"powershell get-childitem E:\\WRT\\Downloads\\TouchGesturesVisio -Recurse ^|select BaseName,Extension ^|unblock-file" 

我需要能夠做到這一點的一個獨立的應用程序,但到目前爲止,我只能得到一個小命令起作用。

當我從應用程序運行命令時,出現以下異常。

powershell get-childitem E:\WRT\Downloads\TouchGesturesVisio -Recurse ^|select B 
aseName,Extension ^|unblock-file 
Error unblock-file : The input object cannot be bound to any parameters for the 

Error command either because the command does not take pipeline input or the inp 
ut 
Error and its properties do not match any of the parameters that take pipeline i 
nput. 
Error At line:1 char:88 
Error + ... ame,Extension |unblock-file 
Error +     ~~~~~~~~~~~~ 
Error  + CategoryInfo   : InvalidArgument: (@{BaseName=ReadMe; Extensi 
on=. 
Error txt}:PSObject) [Unblock-File], ParameterBindingException 
Error  + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Com 
mand 
Error s.UnblockFileCommand 
Error 
Error unblock-file : The input object cannot be bound to any parameters for the 

Error command either because the command does not take pipeline input or the inp 
ut 
Error and its properties do not match any of the parameters that take pipeline i 
nput. 
Error At line:1 char:88 
Error + ... ame,Extension |unblock-file 
Error +     ~~~~~~~~~~~~ 
Error  + CategoryInfo   : InvalidArgument: (@{BaseName=Touc...Extensio 
n=.v 
Error ss}:PSObject) [Unblock-File], ParameterBindingException 
Error  + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Com 
mand 
Error s.UnblockFileCommand 
Error 
Error unblock-file : The input object cannot be bound to any parameters for the 

Error command either because the command does not take pipeline input or the inp 
ut 
Error and its properties do not match any of the parameters that take pipeline i 
nput. 
Error At line:1 char:88 
Error + ... ame,Extension |unblock-file 
Error +     ~~~~~~~~~~~~ 
Error  + CategoryInfo   : InvalidArgument: (@{BaseName=Touc...Extensio 
n=.v 
Error st}:PSObject) [Unblock-File], ParameterBindingException 
Error  + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Com 
mand 
Error s.UnblockFileCommand 
Error 

我知道使用​​的選項,但遺憾的是它不Windows 8.1工作。程序集依賴關係與Windows   8.1混淆。

+0

什麼應用?你還沒有嘗試過我的回答的錯誤 – Raf

回答

1

這是爲我做的。

@"powershell Get-ChildItem 'E:\WRT\Downloads\TouchGesturesVisio' -Recurse -pv f ^| ForEach-Object {unblock-file $_.FullName -whatif}" 

感謝Raf和mjolinor爲您使用的運行PowerShell的指點我到-PipleLineVariable

0

語音標記位置錯誤,您不需要避開反斜槓或使用插入符號。如果您試圖解鎖文件,則不需要中間的select

@powershell "get-childitem E:\WRT\Downloads\TouchGesturesVisio -Recurse |unblock-file" 
+0

我添加了我運行命令時得到的異常。 我不得不轉義角色以允許命令在控制檯應用程序上運行。 – user3373870

+0

你的錯誤'錯誤+ ... ame,Extension | unblock-file'表明你仍然在使用你原來的命令,而不是我的或者mjolinor的。嘗試兩種方式,看看你如何得到 – Raf

0

這是否在您的環境中工作?

@powershell "get-childitem E:\WRT\Downloads\TouchGesturesVisio -Recurse -PipelineVariable File |unblock-file | ft @{l='Name';e={$File.basename}},Extension" 
+0

仍然沒有骰子,文件被解鎖,但我沒有看到名字。 – user3373870

相關問題