Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

passing parameters to script (ps1)

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 10-19-2006   #1 (permalink)
IT Staff
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to a cmdlet in a variable Alastair Smith PowerShell 1 02-08-2008 06:29 AM
Hosting PowerShell & passing parameters to script Dmitry Naumov PowerShell 9 09-24-2007 03:34 AM
Passing parameters to PS script and escaping spaces James PowerShell 2 08-14-2007 07:30 AM
passing [switch] parameters Jeff PowerShell 4 07-28-2007 09:17 AM
Passing parameters to a PS script Dan PowerShell 9 07-17-2007 05:05 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51