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

Resolve Windows 2003 Logon Screen Blackout Problems

The problem:Administrators are unable to logon to a Windows 2003 Server. This is what they…

PowerShell: Checking Computer Type

# Determine what type of Windows machine (client or server)switch ((Get-CimInstance -ClassName Win32_OperatingSystem).ProductType){1 {'client'} #…

PowerShell: Set Virtual Machine Default Paths on Hyper-V Host of a Cluster

$newVirtualMachinePath='D:\VirtualMachines' $newVirtualHardDiskPath='D:\VirtualMachines' function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 =…