SAPIEN Solutions

SAPIEN homepage
PrimalScript script editor+ide
PrimalScope script debugger
Free Tools script utilities
SAPIEN Press tech books
ScriptingAnswers.com learn+share
ScriptingOutpost.com online store
Blog.Sapien.com official blog
Contact Us

 

Targeting a list of names

 This script assumes you have a text file listing one name per line - could be a computer name or a user name. In the example, which uses WMI, it’s a computer name, and the script performs the same operation against each name. There are actually simpler ways, or at least shorter ways, to do this in PowerShell, such as rewriting this as a one-liner. Writing it out like this, however, may make it easier to follow.

  1. # # ScriptingAnswers.com Essentials
  2. # copyright 2006 SAPIEN Technologies, Inc.
  3. # # Target Lists
  4. # # set filename
  5. $file = "c:\computers.txt"

  6. # read names

  7. $names = Get-Content $file

  8. # go through names

  9. foreach ($name in $names) {
  10. # $name has a single name
  11. # do something with it
  12. get-wmiobject Win32_OperatingSystem -computer $name }
  13. Write-Host "Complete."

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , , , , ,

Leave a Reply


Entries (RSS) and Comments (RSS).