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.
- # # ScriptingAnswers.com Essentials
- # copyright 2006 SAPIEN Technologies, Inc.
- # # Target Lists
- # # set filename
- $file = "c:\computers.txt"
-
# read names
- $names = Get-Content $file
-
# go through names
- foreach ($name in $names) {
- # $name has a single name
- # do something with it
- get-wmiobject Win32_OperatingSystem -computer $name }
- Write-Host "Complete."
Tags: list of computers, list of names, list of users, multiple, powershell, wmi










