PowerShell for Windows Admins

Dec 19 2009   7:13AM GMT

Using a script

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

We have seen how to use our script to access information on the local machine. Ideally we want to be accessing this information from many machines across our enterprise. If we save the script to get-os.ps1 we can use it in a few ways.

if we just want information on a handful of computers we can pipe them into the script like this.

".", "127.0.0.1", "rslaptop01" | foreach {"`n $_"; .\Get-OS.ps1 -computer $_ }

I’m running these scripts from the folder where I saved the script which is why I need ./ to represent the path of the current folder.  $_ is the object on the pipeline and `n is the way a new line is thrown.  A ; is used as a line terminator in PowerShell. It is only really used when we are typing at the prompt like this.

Import-Csv ./computers.csv | foreach { "`n"; $_.Computer ; .\Get-OS.ps1 -computer $_.Computer}

If we have a lot of computers – and we want to use the list in a number of scripts we can create a csv file. use a single column with a header of computer like this

Computer
.
localhost
127.0.0.1
rslaptop01

We can input computer names or IP addresses.

Now we know how to access information about our machine’s OS its time to see what else we can do.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: