$cred = Get-Credential
$getinfo = Import-Csv C:\Users\Soma\Desktop\COMPUTERS.csv
$getinfo | foreach {
$OldServer = $.Oldserver
$NewServer = $.NewServer
Write-Output “############# PING #############”
PING $OldServer
PING $NewServer
Write-Output “############# IP_CONFIG #############”
Get-WmiObject Win32_NetworkAdapterConfiguration -cn $oldServer -Cr $cred | ft -AutoSize
Write-Output “############# NS_LOOKUP #############”
nslookup $NewServer
nslookup $oldServer
Write-Output “############# COMPUTER_NAME_INFO ##############”
Get-WmiObject win32_computersystem -cn $oldServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_SERVICES #############”
get-wmiobject win32_Service -cn $oldserver -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_PROCESS ##############”
Get-WmiObject win32_process -cn $oldServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_DISKINFO ##############”
Get-WmiObject win32_logicaldisk -cn $oldServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_OU ##############”
Get-ADOrganizationalunit -filter ‘name -like “*”’ -properties canonicalname
Write-Host -ForegroundColor Red -BackgroundColor Yellow “<<<<<<<<<<>>>>>>>>>>>>>”
Rename-Computer -ComputerName $OldServer -NewName $NewServer -DomainCredential $cred -Restart -Confirm
Write-host -ForegroundColor Red -BackgroundColor Yellow **************** PLEASE WAIT WHILE YOUR COMPUTER/S RESTART ****************
Write-Output “###################################### POST-RENAME DETAILS ########################################################”
( if Test-Connection -Computername $NewServer -BufferSize 32 -Count 10 -ea 1 -quiet)
Write-Output “############# FLUSH_DNS #############”
ipconfig /flushdns
ipconfig /registerdns
Write-Output “############# PING #############”
PING $NewServer
PING $OldServer
Write-Output “############# IP_CONFIG #############”
Get-WmiObject Win32_NetworkAdapterConfiguration -cn $NewServer -Cr $cred | ft -AutoSize
Write-Output “############# NS_LOOKUP #############”
nslookup $NewServer
nslookup $oldServer
Write-Output “############# COMPUTER_NAME_INFO ##############”
Get-WmiObject win32_computersystem -cn $NewServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_SERVICES #############”
get-wmiobject win32_Service -cn $NewServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_PROCESS ##############”
Get-WmiObject win32_process -cn $NewServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_DISKINFO ##############”
Get-WmiObject win32_logicaldisk -cn $NewServer -Cr $cred | ft -AutoSize
Write-Output “############# COMPUTER_OU ##############”
Get-ADOrganizationalunit -filter ‘name -like “*”’ -properties canonicalname
Write-host -ForegroundColor Red -BackgroundColor Yellow **************** RENAME COMPLETED ON SELECTED SERVERS **************** } | Out-File C:\Users\Soma\Desktop\RENAMETEST1.txt
if statement doesn’t seem to work in the above script, I’m unable to ascertain where im doing wrong, all im trying to do is run the #### POST-RENAME DETAILS ### commands if " ( if Test-Connection -Computername $NewServer -BufferSize 32 -Count 10 -ea 1 -quiet)" newserver name which got renamed gets at least one successful ping.
Any help please TIA