Saturday, January 24, 2015

Rename domain controller ComputerName


While setting up my Active directory lab, I forgot to rename the name on domain controller. You can use this procedure to rename domain controller name. Here I am going to use NETDOM command line utility. Although you can rename it through graphical user interface by using the System Properties but that is not recommended method by Microsoft. 

Open Powershell (Run as administrator) on the domain controller where you want to change the hostname. 

Here for demo purpose I have ran below command to check how many domain controllers I have.

Get-ADDomain | Select ReplicaDirectoryServers


And the next command is $env:COMPUTERNAME shows what is the current name is. This way I can ensure I am renaming correct host.

Once you verify that you are on correct domain controller, below command i have run  to add new domain controller name

netdom computername WIN-BDUEMS81I1N /add:AD002

WIN-BDUEMS81I1N is my existing host name which i want to change to AD002.

It will ask for confirmation proceed pressing Y. once command is successful fire next command. this command will make AD002 as primary name.

netdom computername WIN-BDUEMS81I1N /makeprimary:AD002

Once the command executed successfully restart computer. After reboot check the system properties or run hostname command in command prompt to verify that server name has been changed correctly.


And below is the final command to remove old server name.

Netdom computername AD002 /makeprimary:WIN-BDUEMS81I1N
 

Troubleshooting and Verification

To verify everything is successful I check nslookup for the server from desktop in the vcloud.lab domain. 

I got failure message. after checking in DNS server I still found the old entry. at this point just restart server once to get the name register in DNS correctly if this doesn't resolve the issue. Add primary DNS suffix in system properties > Computer Name > Change > More. and restart server once.


This should resolve your issue. incase if you are still getting nslookup error. check if old computer entry is still present in DNS if yes then remove it and add this domain controller's entry.

Deleting old entry.


Adding new entry for AD002.


Once you get this successful, check AD related entries in DNS whether they are reflecting new name correctly.

   
Next step is to check replication and DCDIAG for any errors, I checked repadmin /replsum to see summary of replication and it was successful.

While checking dcdiag I got below failure messages and i will be correcting those in next blog DCDIag - failed test DFSREvent.

Starting test: DFSREvent
   There are warning or error events within the last 24 hours after the SYSVOL has been shared.  Failing SYSVOL replication problems may cause Group Policy problems.
   ......................... AD002 failed test DFSREvent
 

Tuesday, January 20, 2015

CPU Ready animation and powercli Script to pull info

CPU is one of the most critical resource in ESXi and if vCPUs on VMs are not configured correctly (over sized) or , it causes lower performance. To rectify any performance related issues you can always check one of the metric - CPU ready value. (Personally I have observed sometimes Storage or Network latency can be caused by higher CPU ready value)

When VM requires CPU time and physical CPU is busy serving other VMs request. VM has to wait for CPU time, It causes in CPU ready time increment. if values goes around or beyond 5 you have to look into it.


Here I have made this small video example to tried make other understandable how Esxi with busy VMs (vCPU) can degrade performance and increment in CPU ready value.




If you CPU ready value is going above value 5 then its time to take some actions. Below powercli script pulls information from performance tab and convert CPU ready summation value into TOP ready%

 
  #####################################   
  ## http://kunaludapi.blogspot.com   
  ## Version: 1   
  ## Tested this script on successfully  
  ## 1) Powershell v3   
  ## 2) Windows 7
  ## 3) vSphere 5.1 (vcenter, esxi, powercli)
  #####################################   
function Get-Ready {  
   <#  
   .SYNOPSIS  
   This single function provide multiple reports and information. ie: convert ready value to readable format (for realtime, day, week, month, year).  
   .DESCRIPTION  
   This single function provides multiple information from esxi host, as list below,  
   VM's CPU usage, CPU usage Mhz, CPU ready  
   vCPU allocated to VM (breaked into Sockets and Core)  
   VMHost Name   
   Physical CPU information of VMhost (breaked into Sockets and Core)  
   To convert between the CPU ready summation value in vCenter's performance charts and the CPU ready % value that you see in esxtop, you must use a formula.  
   The formula requires you to know the default update intervals for the performance charts. These are the default update intervals for each chart:   
   Realtime: 20 seconds  
   Past Day: 5 minutes (300 seconds)  
   Past Week: 30 minutes (1800 seconds)  
   Past Month: 2 hours (7200 seconds)  
   Past Year: 1 day (86400 seconds)  
   To calculate the CPU ready % from the CPU ready summation value, use this formula:  
   (CPU summation value / (<chart default update interval in seconds> * 1000)) * 100 = CPU ready %  
   Example: The Realtime stats for a virtual machine in vCenter might have an average CPU ready summation value of 1000. Use the appropriate values with the formula to get the CPU ready %.  
   (1000 / (20s * 1000)) * 100 = 5% CPU ready  
   For more infor check on vmware KB 2002181   
   .PARAMETER VM  
   Virtual machine name  
   .INPUTS  
   String.System.Management.Automation.PSObject.  
   .OUTPUTS  
   None.  
   .EXAMPLE  
   PS>Get-VMHost esxihost.fqdn | Get-Ready  
   If you wrap this script inside function you can use it as a command. For more information on using this script check http://kunaludapi.blogspot.com  
   Retrive report for vm from perticular VMHost  
   .NOTES  
   To see the examples, type: "get-help Set-VMHostSSH -examples".  
   For more information, type: "get-help Set-VMHostSSH -detailed".  
   For technical information, type: "get-help Set-VMHostSSH -full".  
   #>  
   [CmdletBinding()]  
   param(  
   [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]  
   [String]$Name) #param  
   begin {Add-PSSnapin vmware.vimautomation.core}#begin  
   process {  
     $Stattypes = "cpu.usage.average", "cpu.usagemhz.average", "cpu.ready.summation"  
     foreach ($esxi in $(Get-VMHost $Name)) {  
       $vmlist = $esxi | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"}  
       $esxiCPUSockets = $esxi.ExtensionData.Summary.Hardware.NumCpuPkgs   
       $esxiCPUcores = $esxi.ExtensionData.Summary.Hardware.NumCpuCores/$esxiCPUSockets  
       $TotalesxiCPUs = $esxiCPUSockets * $esxiCPUcores  
       foreach ($vm in $vmlist) {  
         $VMCPUNumCpu = $vm.NumCpu  
         $VMCPUCores = $vm.ExtensionData.config.hardware.NumCoresPerSocket  
         $VMCPUSockets = $VMCPUNumCpu / $VMCPUCores  
         $GroupedRealTimestats = Get-Stat -Entity $vm -Stat $Stattypes -Realtime -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId  
         $RealTimeCPUAverageStat = "{0:N2}" -f $($GroupedRealTimestats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $RealTimeCPUUsageMhzStat = "{0:N2}" -f $($GroupedRealTimestats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $RealTimeReadystat = $GroupedRealTimestats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average  
         $RealTimereadyvalue = [math]::Round($(($RealTimeReadystat / (20 * 1000)) * 100), 2)  
         $Groupeddaystats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-1) -Finish (get-date) -IntervalMins 5 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId  
         $dayCPUAverageStat = "{0:N2}" -f $($Groupeddaystats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $dayCPUUsageMhzStat = "{0:N2}" -f $($Groupeddaystats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $dayReadystat = $Groupeddaystats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average  
         $dayreadyvalue = [math]::Round($(($dayReadystat / (300 * 1000)) * 100), 2)  
         $Groupedweekstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-7) -Finish (get-date) -IntervalMins 30 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId  
         $weekCPUAverageStat = "{0:N2}" -f $($Groupedweekstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $weekCPUUsageMhzStat = "{0:N2}" -f $($Groupedweekstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $weekReadystat = $Groupedweekstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average  
         $weekreadyvalue = [math]::Round($(($weekReadystat / (1800 * 1000)) * 100), 2)  
         $Groupedmonthstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-30) -Finish (get-date) -IntervalMins 120 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId  
         $monthCPUAverageStat = "{0:N2}" -f $($Groupedmonthstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $monthCPUUsageMhzStat = "{0:N2}" -f $($Groupedmonthstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $monthReadystat = $Groupedmonthstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average  
         $monthreadyvalue = [math]::Round($(($monthReadystat / (7200 * 1000)) * 100), 2)        
         $Groupedyearstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-365) -Finish (get-date) -IntervalMins 1440 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId  
         $yearCPUAverageStat = "{0:N2}" -f $($Groupedyearstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $yearCPUUsageMhzStat = "{0:N2}" -f $($Groupedyearstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)  
         $yearReadystat = $Groupedyearstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average  
         $yearreadyvalue = [math]::Round($(($yearReadystat / (86400 * 1000)) * 100), 2)    
         $data = New-Object psobject  
         $data | Add-Member -MemberType NoteProperty -Name VM -Value $vm.name  
         $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUs -Value $VMCPUNumCpu   
         $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUSockets -Value $VMCPUSockets  
         $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUCores -Value $VMCPUCores  
         $data | Add-Member -MemberType NoteProperty -Name "RealTime Usage Average%" -Value $RealTimeCPUAverageStat  
         $data | Add-Member -MemberType NoteProperty -Name "RealTime Usage Mhz" -Value $RealTimeCPUUsageMhzStat  
         $data | Add-Member -MemberType NoteProperty -Name "RealTime Ready%" -Value $RealTimereadyvalue  
         $data | Add-Member -MemberType NoteProperty -Name "Day Usage Average%" -Value $dayCPUAverageStat  
         $data | Add-Member -MemberType NoteProperty -Name "Day Usage Mhz" -Value $dayCPUUsageMhzStat  
         $data | Add-Member -MemberType NoteProperty -Name "Day Ready%" -Value $dayreadyvalue  
         $data | Add-Member -MemberType NoteProperty -Name "week Usage Average%" -Value $weekCPUAverageStat  
         $data | Add-Member -MemberType NoteProperty -Name "week Usage Mhz" -Value $weekCPUUsageMhzStat  
         $data | Add-Member -MemberType NoteProperty -Name "week Ready%" -Value $weekreadyvalue  
         $data | Add-Member -MemberType NoteProperty -Name "month Usage Average%" -Value $monthCPUAverageStat  
         $data | Add-Member -MemberType NoteProperty -Name "month Usage Mhz" -Value $monthCPUUsageMhzStat  
         $data | Add-Member -MemberType NoteProperty -Name "month Ready%" -Value $monthreadyvalue  
         $data | Add-Member -MemberType NoteProperty -Name "Year Usage Average%" -Value $yearCPUAverageStat  
         $data | Add-Member -MemberType NoteProperty -Name "Year Usage Mhz" -Value $yearCPUUsageMhzStat  
         $data | Add-Member -MemberType NoteProperty -Name "Year Ready%" -Value $yearreadyvalue  
         $data | Add-Member -MemberType NoteProperty -Name VMHost -Value $esxi.name  
         $data | Add-Member -MemberType NoteProperty -Name VMHostCPUSockets -Value $esxiCPUSockets  
         $data | Add-Member -MemberType NoteProperty -Name VMHostCPUCores -Value $esxiCPUCores  
         $data | Add-Member -MemberType NoteProperty -Name TotalVMhostCPUs -Value $TotalesxiCPUs  
         $data  
       } #foreach ($vm in $vmlist)  
     }#foreach ($esxi in $(Get-VMHost $Name))  
   } #process  
 } #Function Get-Ready  

How to you use this script. Here I will save above command in powershell profile script.

Make sure you have downloaded and installed powercli. Open powercli as a administrator (Demo: how to open powercli). if you see any errors in red regarding execution policy make sure your you are allowed to run PS1 files by running command

Set-ExecutionPolicy RemoteSigned -Confirm:$true


Make note of the location and create the Microsoft.PowerShell_profile.ps1 or run Notepad $profile to create a file at the location (you might also need to create a folder as well if not created earlier)


Save the file, Close Powercli console and open it again.
Connect to vCenter Server. now you are ready to get the report. You have to run below command and output it to CSV file.




This is a personal weblog. The opinions expressed here represent my own and not those of my employer.


While every caution has been taken to provide my readers with most accurate information and honest analysis, please use your discretion before taking any decisions based on the information in this blog. Author will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.

Saturday, January 3, 2015

Retaining IP address when doing VM network adapter changes

In my one of the blog written long time back Changing network adapter type in VMware some of the users reported after doing VM network adapter type they are not able to retain, below dos command on the windows will be helpful, if you want to retain IPs and apply it through scripting.


 netsh interface ip dump > c:\ipaddress.txt  



If you open ipaddress.txt file, you will find below information.
 # ----------------------------------  
 # IPv4 Configuration  
 # ----------------------------------  
 pushd interface ipv4  
 reset  
 set global icmpredirects=enabled  
 add route prefix=0.0.0.0/0 interface="Local Area Connection 2" nexthop=192.168.33.254 publish=Yes  
 add address name="Local Area Connection 2" address=192.168.33.34 mask=255.255.255.0  
 popd  
 # End of IPv4 configuration  

you just need to be sure changed new added or modified Network adapter interface name should match.

for restoring IP address information use below command.

 netsh -c interface -f c:\temp\ipaddress.txt  








Friday, January 2, 2015

Get report on VM Hot add CPU and Memory feature

This is my first blog in new year 2015

I recently receive query from my colleague on fetching Hot add CPU and Hot add memory feature for all VMs. below is a one liner powercli script which will pull the data in CSV format.

 Get-VM | Select-Object Name, VMHost, @{N="CpuHotAddEnabled"; E={$_.ExtensionData.config.CpuHotAddEnabled}}, @{N="MemoryHotAddEnabled"; E={$_.ExtensionData.config.MemoryHotAddEnabled}} | Export-Csv -NoTypeInformation -Path c:\temp\vcenterlist.csv  

What information above script is collecting?
Name of VM,
VMhost
CPUHOTADDENABLED status (True or false)
MEMORYHOTADDENABLED status (True or false)

Report will look like this xlsx file.


For individual VM you can check this setting at righclick VM > Edit settings > options> Memory/CPU Hotplug