2014-05-01 39 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

相关问题