Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Powershell Invoke-Item and cmd line parameters

Reply
 
Old 05-06-2008   #1 (permalink)
Damian


 
 

Powershell Invoke-Item and cmd line parameters

I am trying to use powershell to execute a net use command on many
machines. Unfortunately, I can not get the cmd line parameters to
parse properly. Could you assist in this endevour.

Thanks.

$Computer = get-QADComputer -SearchRoot 'frabrikam/Enterprise-
Applications/Business-Systems/MS/Admin-Systems'| foreach-object
{$_.name}

foreach ($i in $Computer){
$command = "\\"+ $i
$command2 = "D:\Sysinternals\psexe.exe "+ $command +"Net use m: \
\servershare\subfolder "
Invoke-Item $command2
}

My System SpecsSystem Spec
Old 05-06-2008   #2 (permalink)
Keith Hill [MVP]


 
 

Re: Powershell Invoke-Item and cmd line parameters

"Damian" <damian.yates@xxxxxx> wrote in message
news:ba8545c3-a07f-468f-b5ae-fafd2868bb82@xxxxxx
Quote:

> I am trying to use powershell to execute a net use command on many
> machines. Unfortunately, I can not get the cmd line parameters to
> parse properly. Could you assist in this endevour.
>
> Thanks.
>
> $Computer = get-QADComputer -SearchRoot 'frabrikam/Enterprise-
> Applications/Business-Systems/MS/Admin-Systems'| foreach-object
> {$_.name}
>
> foreach ($i in $Computer){
> $command = "\\"+ $i
> $command2 = "D:\Sysinternals\psexe.exe "+ $command +"Net use m: \
> \servershare\subfolder "
> Invoke-Item $command2
> }
I think the exe should be PSExec.exe, right? And in your scenario you would
want to use Invoke-Expression instead of Invoke-item. Invoke-Item is more
for using the ShellExecute capabilities of Windows e.g. invoke-item foo.xls
opens Excel and loads foo.xls. But I wouldn't use Invoke-Expression either.
I would execute psexec directly like so:

$computers | Foreach {d:\Sysinternals\psexec.exe "\\$_" "net use m:
\\server\sharename"}

--
Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Invoke Scriptblock with parameters in a new thread PowerShell
Invoke-Item with param. PowerShell
Foreground Invoke-Item PowerShell
Another Invoke-Item question PowerShell
Invoke-Item and passing command line parameters PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46