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 - Parameters

Reply
 
Old 01-04-2008   #1 (permalink)
Pimp Daddy


 
 

Parameters

I have the following code in a script called 'IP':

function total()
{
ipconfig -all
}

function MAC()
{
$Name = ipconfig -all | findstr "Physical";
$Name.Replace("Physical", "MAC")
}

function IPAdd()
{
ipconfig | findstr "IP"
}

function subnet()
{
ipconfig -all | findstr "Subnet"
}



What do I need to add so I can e.g. call the MAC function by doing this at
the command line?:

../IP -MAC

My System SpecsSystem Spec
Old 01-04-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Parameters

Pimp Daddy wrote:
Quote:

> I have the following code in a script called 'IP':
>
> function total()
> {
> ipconfig -all
> }
>
> function MAC()
> {
> $Name = ipconfig -all | findstr "Physical";
> $Name.Replace("Physical", "MAC")
> }
>
> function IPAdd()
> {
> ipconfig | findstr "IP"
> }
>
> function subnet()
> {
> ipconfig -all | findstr "Subnet"
> }
>
>
>
> What do I need to add so I can e.g. call the MAC function by doing this at
> the command line?:
>
> ./IP -MAC
Try someting like this:

function IP {
if ($args -contains "-total") {ipconfig -all}
if ($args -contains "-mac"){
$Name = ipconfig -all | findstr "Physical"
$Name|foreach-object {$_.Replace("Physical", "MAC")}
}
if ($args -contains "-ipadd") {ipconfig | findstr "IP"}
if ($args -contains "-subnet"){
ipconfig -all | findstr "Subnet"
}
}

PSH> . ./IP.ps1
PSH> IP -MAC
MAC Address. . . . . . . . . : xxxxxxxxxxxxxx
....

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 01-04-2008   #3 (permalink)
Shay Levi


 
 

Re: Parameters



function IP ($pattern){

switch ($pattern){

"mac" {
$Name = ipconfig -all | findstr "Physical"
$Name | foreach {$_.Replace("Physical", "MAC")}
break;

}

"ipadd" { ipconfig | findstr "IP" ; break}
"subnet" { ipconfig -all | findstr "Subnet"; break}
default { ipconfig -all; break}
}

}



IP # get total
IP mac # get mac
IP subnet # get subnet

Also, read about the select-string. It's the PowerShell findstr 'equivalent',
for more help, type:

help select-string -full

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


Quote:

> I have the following code in a script called 'IP':
>
> function total()
> {
> ipconfig -all
> }
> function MAC()
> {
> $Name = ipconfig -all | findstr "Physical";
> $Name.Replace("Physical", "MAC")
> }
> function IPAdd()
> {
> ipconfig | findstr "IP"
> }
> function subnet()
> {
> ipconfig -all | findstr "Subnet"
> }
> What do I need to add so I can e.g. call the MAC function by doing
> this at the command line?:
>
> ./IP -MAC
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
parameters in .net .NET General
Far Cry parameters Vista Games
environment parameters Vista installation & setup
Parameters with ScriptMethod? 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