Posted On March 29, 2019

Check Servers NSLookup of a Listener to Match Active Node IP

kimconnect 0 comments
blog.KimConnect.com >> Codes , Database >> Check Servers NSLookup of a Listener to Match Active Node IP
$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"    
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

RDP Gateway with MFA

Step 1: Install RDS Gateway   Prerequisites: 1. Enable Power Shell Remoting  2. SSL Certs…

Basic CSS: Give a Background Color to a div Element

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style>.red-text {color: red;}h2 {font-family: Lobster, monospace;}p {font-size: 16px;font-family: monospace;}.thick-green-border {border-color: green;border-width: 10px;border-style:…

PowerShell: Rename Photo and Video Files by Adding Creation Dates

Have you ever downloaded a punch of images, MOV, and MP4 from iCloud to find…