Thread: Parameters
View Single Post
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