$servers="SQL01","SQL02","SQL03","SQL04" $listener="halistener01" $activeNode="10.10.10.5" # Dynamic Credential method 1 $who = whoami if ($who.Substring($who.length-2, 2)="-admin"){$username=$who;} else {$username=$who+"-admin";} $password = Read-Host -Prompt "Input the password for account $username" -AsSecureString $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password $elevate = New-PSSession -ComputerName localhost -Credential $cred foreach ($server in $servers){ #$ip=(invoke-command -Session $elevate -ScriptBlock {(nslookup $Args[0] | Select-String Address | Where-Object LineNumber -eq 5).ToString().Split(' ')[-1];} -Args $listener) $ip=(invoke-command -Session $elevate -ScriptBlock {(Resolve-DnsName $Args[0]).IPAddress;} -Args $listener) $result= if ([IPAddress]$ip.Trim() -eq [IPAddress]$activeNode.Trim()){"Pass";}else{"fail";}; $server+": $result" }
March 29, 2019March 29, 2019
0 Comments