0

How can I execute multiple commands in PowerShell on one line?

I am trying to unlock the files in the directory and output their names:

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

I need to be able to do this in a stand-alone application, but so far I can only get one cmdlet to function.

When I run the command from the application, I get the following exception.

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

I know about the option to use System.Management.Automation, but unfortunately it doesn't work on Windows 8.1. The assembly dependencies are messed up with Windows 8.1.

1
  • what app are you using to run the powershell? the errors you haven't tried my answer Commented May 1, 2014 at 9:21

3 Answers 3

0

Speechmarks are in the wrong place and you don't need to escape backslashes or use carets. If you are trying to unblock files you don't need the intermediate select either.

@powershell "get-childitem E:\WRT\Downloads\TouchGesturesVisio -Recurse |unblock-file"
Sign up to request clarification or add additional context in comments.

2 Comments

I added the exception I get when I run the command. I had to escape the characters to allow the command to run on the console app.
your errors Error + ... ame,Extension |unblock-file show you are still using your original command rather than mine or @mjolinor's. try both and see how you get on
0

Does this work in your environment?

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

1 Comment

Still no dice, the files are getting unlocked, but I don't see the names.
0

This did it for me.

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

Thanks Raf and mjolinor for pointing me to the -PipleLineVariable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.