input - Powershell - Script that accepts single string param or filelist using Get-Content -
i'm having trouble getting powershell accept single string param input on command line or accept file input containing list of servers.
i've tried working this example can't things work.
i tried working param([switch] $filelist)
if
statement doesn't reach else
block.
what hope put script accepts single server name passed in on command line or accepts input text file. appreciate pointers!
-edit, using below running script with/without param returns run on single server
, same if (($filelist -eq $false))
using keith hill's example, again no matter try passing script output same (the if block never reaches else
block)
-edit2, second code example works when passing single server name script, problem me trying [switch]
parameter accept filename , pass code block foreach
loop. errors following get-eventlog : invalid value '.\fake.txt' parameter 'machinename'.
@ else line.
param([switch] $filelist) if (($filelist -eq $true)) { "no file list input" } else { "run on single server"}
2nd code example
param( [switch]$filelist, [string]$server) if ($filelist -eq $true) { $list = gc $filelist foreach ($server in $list){get-eventlog -computername $server -logname system | where-object {$_.eventid -eq '6005'} | select timegenerated,message | select -first 1}#end foreach } else{ get-eventlog -computername $server -logname system | where-object {$_.eventid -eq '6005'} | select timegenerated,message | select -first 1 }
if you're set on using switch parameter won't if want single parameter can file or server name will.
param ( [parameter(mandatory = $true)] [string]$filelist ) if (test-path $filelist) { "file found, file related commands." } else { "single server actions." }
Comments
Post a Comment