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.

“.”, “”, “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


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.

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:

Share this item with your network: