Wednesday, 15 August 2012

powershell - Term ' ' is not recognized as the name of a cmdlet -



powershell - Term ' ' is not recognized as the name of a cmdlet -

i'm trying run in 1 line using "run" command:

powershell -noexit ; get-childitem -recurse -force -include *.ost \\pchostname\c$\users -erroraction "silentlycontinue" | ls | select-object name, @{name="gigabytes";expression={$_.length / 1gb}}

but error:

gigabytes : term 'gigabytes' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify path right , seek again. @ line:1 char:137 + ... t name, @{name=gigabytes;expression={$_.length / 1gb}} + ~~~~~~~~~ + categoryinfo : objectnotfound: (gigabytes:string) [], commandnotfoundexception + fullyqualifiederrorid : commandnotfoundexception

the code works on started powershell window without powershell -noexit ;.

any ideas prepare it?

due way command line arguments tokenized through "run", need either escape double quotes around gigabytes (using \ escape character) or substitute them single quotes. either of these 2 select-object commands should work:

select-object name, @{name=\"gigabytes\";expression={$_.length / 1gb}}

or

select-object name, @{name='gigabytes';expression={$_.length / 1gb}}

this because wrapped in double quotes interpreted single argument.

see this reply more detailed explanation how command line arguments tokenized through "run".

powershell powershell-v2.0

No comments:

Post a Comment