8,330 questions
Here's one way.
<#
.SYNOPSIS
This script does something with computers.
.DESCRIPTION
If you specify a CSV, be sure to have a column named computername.
This script accepts these parameters.
-computername A single computer name.
-csv The fully qualified path to a csv file that has a computername column.
-txt The fully qualified path to a txt file that contains names of computers.
.NOTES
.LINK
http://www.google.com
Author: MotoX80 on Microsoft Q&A Forums
#>
Param( #https://powershell.org/2013/05/a-helpful-message-about-helpmessage/
[String]$computername,
[String]$csv,
[String]$txt
)
if ($computername) {
$hosts = $computername
} elseif ($csv) {
if (Test-Path $csv) {
$hosts = (Import-Csv $CSV).computername
} else {
"CSV file not found."
return
}
} elseif ($txt) {
if (Test-Path $txt) {
$hosts = Get-Content $txt
} else {
"TXT file not found."
return
}
} else {
"Error. You must specify one parameter."
return
}
foreach($name in $hosts) {
"Processing $name"
}