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 - passing parameters to script (ps1)

Reply
 
Old 10-19-2006   #1 (permalink)
IT Staff


 
 

passing parameters to script (ps1)

i have the following command in my ps1 script :

get-wmiobject Win32_ComputerSystem -computername 155.14.197.22 |
format-table -property username

I wish to change to following :

get-wmiobject Win32_ComputerSystem -computername <this becomes a parameter,
and how to make it a parameter> | format-table -property username

From my cmd prompt, how do i call the scripts filling in the parameters

eg powershell -command test.ps1 <parameter 1>, etc



My System SpecsSystem Spec
Old 10-19-2006   #2 (permalink)
dreeschkind


 
 

RE: passing parameters to script (ps1)

"IT Staff" wrote:

> i have the following command in my ps1 script :
>
> get-wmiobject Win32_ComputerSystem -computername 155.14.197.22 |
> format-table -property username
>
> I wish to change to following :
>
> get-wmiobject Win32_ComputerSystem -computername <this becomes a parameter, and how to make it a parameter> | format-table -property username


Try someting like:

get-wmiobject Win32_ComputerSystem -computername $args[0] | format-table
-property username
# $args[0] is the first parameter of your script, $args[1] the second, etc.

> From my cmd prompt, how do i call the scripts filling in the parameters
>
> eg powershell -command test.ps1 <parameter 1>, etc


you guessed correctly:

PS>get-content C:\do-foo.ps1
write-host 'test0'
write-host $args[0]
write-host $args[1]

cmd> powershell -command c:\do-foo.ps1 test1 test2
test0
test1
test2

--
greetings
dreeschkind
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Passing parameters to a PS script PowerShell
Help with PS wretched way of passing parameters to executables PowerShell
Hosting PowerShell & passing parameters to script PowerShell
Passing parameters to PS script and escaping spaces PowerShell
passing [switch] 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