PowerShell: Remotely rename Windows Computers from CSV file
I recently setup a bunch of Windows 7 VDI systems for a customer. They asked if they could rename them to a different naming convention. I definitely didn’t want to have to login to each one or run psexec. Thankfully with Windows Management Framework(a prerequisite) & Powershell this is very straight forward.
1st Step: Run Get-ADComputer with your desired filter and export to CSV file for use in step 3. All of my new VDI systems contained the syntax “vdi” so I used this as my filter.
Get-ADComputer -Filter {Name -like “*vdi*”} | select-object Name | Export-Csv .\RenameComputers.csv -NoTypeInformation
2nd Step:
Open your new CSV in Excel and add a new row called “NewName”, add the corresponding new computer names & save:
3rd Step:
Prompts for credentials used to connect to the machine remotely, imports the csv, runs the rename-computer cmdlet using the content Name & NewName from the CSV & renames the computer.
$cred = get-credential
$Computers = import-csv .\RenameComputers.csv
foreach ($Computer in $Computers){
Rename-Computer -NewName $Computer.NewName -ComputerName $Computer.Name -DomainCredential $cred -Restart
}
Powershell: get-vmwitch, get-vm, etc. blank
Recently when running a get-vmswitch on a Hyper-V host I noticed that the content came back blank. The key is you have to run your PowerShell session as an Administrator. Doh! If you notice you are not getting results, might pay to give it a go. Sometimes it’s the simple things! 🙂
Powershell: get-vmswitch, get-vm, etc. blank
Recently when running a get-vmswitch PowerShell command on a Hyper-V host I noticed that the content came back blank. Even though I was a local admin on the host, I still needed to run my PowerShell session as an Administrator. Doh! If you notice you are not getting results, might pay to give it a go. 🙂
Remotely set DNS Primary and Secondary Servers via PowerShell
Create a text file with a list of server names that you would like to change Primary & Secondary DNS for:
#PowerShell Script:
$computer = get-content C:\temp\servers.txt
$DNSServers = “192.168.1.19”,”192.168.1.30″
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
Foreach($NIC in $NICs) {$NIC.SetDNSServerSearchOrder($DNSServers), $NIC.SetDynamicDNSRegistration(“TRUE”)}
SharePoint slow to load after server restart
We have recently deployed a SharePoint 2013 Enterprise rollout for a customer. After a period of inactivity, server restart or IISRESET the first time the various sites were browsed there was a noticeable (10sec+) lag in displaying the page. After some research it appears that this is a common SharePoint/IIS issue due to IIS Applications recycling their worker processes. The work around for this is a warmup script which will navigate to the various pages and “warm them up.” This can be used either by a) Simply running the script (remembering to run Set-ExecutionPolicy first) or b) By running SPBestWarmUp.ps1 -install which will install it as a scheduled task to run every hour.
Here’s a link to the script: https://spbestwarmup.codeplex.com/