mazdajai's Posts

Thanks. I added 'Disconnect-VIServer * -Force -Confirm:$False' but there is an issue when one of them fail: Time :: host :: Runtime (seconds) 12:06:49 :: bavc1 :: 1286.3862268 13:17:41 :... See more...
Thanks. I added 'Disconnect-VIServer * -Force -Confirm:$False' but there is an issue when one of them fail: Time :: host :: Runtime (seconds) 12:06:49 :: bavc1 :: 1286.3862268 13:17:41 :: bvc1:: 4252.2041729 13:30:23 :: lvc1:: 761.6258825 13:30:30 :: lxdvc :: EXCEPTION! 13:34:00 :: lxvc1:: EXCEPTION! 13:37:28 :: nvc2:: EXCEPTION! 13:40:55 :: svc1:: EXCEPTION! 13:46:52 :: stavc1:: EXCEPTION! 13:53:28 :: zvc1:: EXCEPTION! I restricted the get-vm to get-vm *abc* to speed up the troubleshooting and found the culprit - there was a global attribute missing one of the vc. Time :: host :: Runtime (seconds) 21:01:56 :: bavc1 :: 54.4264154 21:02:23 :: bvc1 :: 27.2972137 21:02:29 :: lvc1 :: 5.9372769 21:02:36 :: lxdvc :: EXCEPTION! 21:02:51 :: lxvc1 :: EXCEPTION! 21:03:04 :: nvc2 :: EXCEPTION! 21:03:16 :: svc1 :: EXCEPTION! 21:03:32 :: stavc1 :: EXCEPTION! 21:03:50 :: zvc1 :: EXCEPTION! By the question is 1) why it skip and HALT! the rest when it fail? 2) Is this new in powercli 6.0? it never happen in 5.5 or older. 21:06:38 :: bavc1 :: 30.5933593 21:06:52 :: bvc1 :: 13.7796256 21:06:57 :: lvc1 :: 5.4512553 21:07:09 :: lxvc1 :: 12.2495468 21:07:22 :: nvc2 :: 12.1385508 21:07:27 :: svc1 :: 5.1842234 21:07:31 :: stavc1 :: 4.1381707 21:07:37 :: zvc1 :: 5.6402636
Updated: I closed the powercli prompt and re-run the script, it seems to be working (with or without the continue statement). It seems like it happens when it has previous connection to the VC... See more...
Updated: I closed the powercli prompt and re-run the script, it seems to be working (with or without the continue statement). It seems like it happens when it has previous connection to the VCs. If I open a new powercli prompt, I don't get the error. I have a line to disconnect-viserver, does it not working? Is there a way to cleanly clear all VC session?
No luck. I have attached an error.log that I send $error to. catch { "$(Get-Date -uformat %H:%M:%S) :: $vcenter :: EXCEPTION" | Out-file -Encoding UTF8 -Append $outlog $error | O... See more...
No luck. I have attached an error.log that I send $error to. catch { "$(Get-Date -uformat %H:%M:%S) :: $vcenter :: EXCEPTION" | Out-file -Encoding UTF8 -Append $outlog $error | Out-file -Encoding UTF8 -Append $errlog continue } Time :: host :: Runtime (seconds) 17:11:40 :: BADVC1:: EXCEPTION 17:18:50 :: GoodVC1:: EXCEPTION
I have a for loop get-vm statement against a list of vcenters with try/catch. For some reason when one of the vcenter fails, the remaining will fail and will not run. Sample list of vcenters.i... See more...
I have a for loop get-vm statement against a list of vcenters with try/catch. For some reason when one of the vcenter fails, the remaining will fail and will not run. Sample list of vcenters.inputs: BadVC1 GoodVC1 <---will not run if BadVC1 fails GoodVC2<---will not run if BadVC1 fails $pwd='d:\'; $vcenters=gc vcenters.input | sort; $invuser='xxx'; $invpass='xxx'; $outlog="$(Get-Date -uformat %m%e%g)_run.log"; $errlog='error.log'; "Time :: host :: Runtime (seconds)" | Out-file -Encoding UTF8 $outlog "$MyInvocation.MyCommand.Definition" | Out-file -Encoding UTF8 $errlog foreach ($vcenter in $vcenters) {     $startsec=Get-Date     $outfile=$vcenter+"_inv.csv" try {     connect-viserver $vcenter -User $vcenter\$invuser -Password $invpass     $Report = @()             Get-VM | % {         $vmcls = $_ | Get-Cluster         $vmnet = $_ | Get-NetworkAdapter         $vmds = $_ | Get-Datastore         $vms = "" | Select-Object Cluster, Host, Name, FQDN, State, OS, Network, Memory, CPU, ServerRole, `         PatchGroup, DataStore, ProvisionedGB, ConsumedGB, Contact, PVU, Replicated, Notes         $vms.Cluster = $vmcls.Name         $vms.Host = $_.VMHost            $vms.Name = $_.Name         $vms.FQDN = $_.Guest.HostName         $vms.State = $_.PowerState         $vms.OS = $_.Guest.OSFullName         $vms.Network = $vmnet.NetworkName         $vms.Memory = $_.MemoryMB         $vms.CPU = $_.NumCpu         $vms.ServerRole = $_.CustomFields.Item("ServerRole")         $vms.PatchGroup = $_.CustomFields.Item("PatchGroup")         $vms.DataStore = $vmds.Name         $vms.ProvisionedGB = $_.ProvisionedSpaceGB         $vms.ConsumedGB = $_.UsedSpaceGB         $vms.Contact = $_.CustomFields.Item("System Contact")         $vms.PVU = $_.CustomFields.Item("PVU")         $vms.Replicated = $_.CustomFields.Item("Replicated")         $vms.Notes = $_.Notes         $Report += $vms        }     $Report | ConvertTo-csv | Out-file -Encoding UTF8 $pwd\data\$outfile     Disconnect-VIServer $vcenter -confirm:$false     $endsec=Get-Date;     "$(Get-Date -uformat %H:%M:%S) :: $vcenter :: $((New-TimeSpan -Start $startsec -End $endsec).TotalSeconds)" | Out-file -Encoding UTF8 -Append $outlog } catch { "$(Get-Date -uformat %H:%M:%S) :: $vcenter :: EXCEPTION" | Out-file -Encoding UTF8 -Append $outlog $error | Out-file -Encoding UTF8 -Append $errlog }    };
Works perfect - Thanks a lot LucD!
Very interesting on computing this using Welford's. I have ran this for couple days and found it is extremely useful! Can you suggest where I should put a filter to only show $stat there is... See more...
Very interesting on computing this using Welford's. I have ran this for couple days and found it is extremely useful! Can you suggest where I should put a filter to only show $stat there is greater than 20 to filter idle vms? Name    StdVar CPU ----    ------ --- vm1   0.14 0.5/0.5/1.4/0.5/0.5/0.6/0.5/0.5/0.5/0.5/0.5/0.5/0.5/1.4/0.5/0.5/0.5/0.5/0.5/1.4/0.5/0.5/0.5/0.5 Thanks!
"the same value for all the intervals" - Yes. This is a symptoms of hung process therefore we are looking to correlate it with vmware. I know a bit of R but don't know anything about it in the... See more...
"the same value for all the intervals" - Yes. This is a symptoms of hung process therefore we are looking to correlate it with vmware. I know a bit of R but don't know anything about it in the powershell world. Will take a look.
Is it possible to capture utilization that was constant in a fixed duration? Yes: For example: 2pm = 20%, 3pm = 20%, 4pm = 20%, 5pm = 20% No: For example: 2pm = 0%, 3pm = 40%, 4pm = 0%, ... See more...
Is it possible to capture utilization that was constant in a fixed duration? Yes: For example: 2pm = 20%, 3pm = 20%, 4pm = 20%, 5pm = 20% No: For example: 2pm = 0%, 3pm = 40%, 4pm = 0%, 5pm = 40% 
We have an environment (500+ vms) where often time there is hung process. We observed one of the indication is stale cpu utilization over a period of time. Let's say if there is a vm with a st... See more...
We have an environment (500+ vms) where often time there is hung process. We observed one of the indication is stale cpu utilization over a period of time. Let's say if there is a vm with a steady 40% cpu utilization over a day, it is safely assume that there is bad process running because an idle process should consuming minimum. That being said. Is it possible to query vms and return vms with stale cpu utilization? I am thinking to use get-stat and look for non-zero value but doesn't seem to working. Any thoughts?
Thank you!!
Thanks. I modified my script and is doing a test run(takes a while). I am measuring the performance, will report back in few hours. $esxName1 = "csms1.example.com" $esxName2 = "*esx*v.exam... See more...
Thanks. I modified my script and is doing a test run(takes a while). I am measuring the performance, will report back in few hours. $esxName1 = "csms1.example.com" $esxName2 = "*esx*v.example.com" $vm = get-vm | Where {$_.VMHost.Name -ne $esxName1 -and $_.VMHost.Name -notlike $esxName2}
Is there a way to exclude a VMhost with get-snapshot? I need to exclude VMs with GuestOS (Windows 7 \ XP) that sits on one VMHost. I can use get-vm + Name or Guest OS filter but it will slow t... See more...
Is there a way to exclude a VMhost with get-snapshot? I need to exclude VMs with GuestOS (Windows 7 \ XP) that sits on one VMHost. I can use get-vm + Name or Guest OS filter but it will slow the entire query down. connect-viserver XXXXX $vm = get-vm $snapshots = Get-Snapshot -VM $vm foreach ( $snap in $snapshots )     {     if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) )         {     $Snap | Select-Object -Property *     @{N="HostName";E={$_.vm}},     @{N="SizeGB";E={[math]::Round($_.SizeGB)}},     @{N="CreatedOn";E={$($_.Created -replace $time)}}     $count++            }     }
I am thinking to produce a daily report of vms with hung process -  vms with an average of cpu utilization 80%+ over the last 4 fours is a sign and needs to be look up. This script will kick o... See more...
I am thinking to produce a daily report of vms with hung process -  vms with an average of cpu utilization 80%+ over the last 4 fours is a sign and needs to be look up. This script will kick off everyday at 5am and sweep 500+ vms, is there anything else I should put in the consideration? $vm = "abcd" $statcpu = Get-Stat -Entity $vm -Stat cpu.usage.average -Start (Get-Date).AddHours(-4) -Finish (Get-Date).AddHours(-0) $Avgcpu = $statcpu | where {$_.Value -ne 0} | Measure-Object -Property value -Average -Maximum | select Average if ($Avgcpu.Average -gt 80) {write-host $vm}
Thank you for the explaination. For some reason, set-VMHostSysLogServer does not reflect the changes. I have reloaded the syslog daemon, set-VMHostSysLogServer reports the updated changes but ... See more...
Thank you for the explaination. For some reason, set-VMHostSysLogServer does not reflect the changes. I have reloaded the syslog daemon, set-VMHostSysLogServer reports the updated changes but not in vCenter. foreach ($esxhost in (Get-Cluster -Name $cluster | Get-VMHost )){     Write-Host "ESX: $esxhost"     $esxcli = Get-EsxCli -VMhost $esxhost        $esxcli.system.syslog.reload() }
Thanks! To have vm name or vm hostname display on the first column, does that mean get-vm or get-vmhost should always be on the first line?
This is the closest way I have, but I am sure there is a more elegant way to do it. (get-vmhost esx04t).Name;(Get-VMHostSysLogServer -vmhost esx04t).Host
This question is probably answered numerous times but I have a hard time figuring the answer, so here it is. Often time I need to combine multiple get statements into the output, for exmaple, ... See more...
This question is probably answered numerous times but I have a hard time figuring the answer, so here it is. Often time I need to combine multiple get statements into the output, for exmaple, Get-NetworkAdapter and Get-VMHostSysLogServer. These get statement do not have the vm or host on the output. How can aggregiate the vm name and host name in the output? For instance: Get-VMHostSysLogServer would generate - Host ---- 10.10.10.1 How can I append the ESX host column in the output? Esx      Host ---          ---- ESX1     10.10.10.1
Thanks LucD and Robert. Got it! Is there there any way to put the special characters in without declaring them into an variable? I miss perl - without have to delcare variable for minor item l... See more...
Thanks LucD and Robert. Got it! Is there there any way to put the special characters in without declaring them into an variable? I miss perl - without have to delcare variable for minor item like this. $time = "\d{1,2}:\d{1,2}:\d{1,2}.*?$" $Snap | Select-Object -Property @{N="HostName";E={$_.vm}}, @{N="SizeGB";E={[math]::Round($_.SizeGB)}},@{N="CreatedOn";E={$($_.Created -replace $time)}}
I tried but didn't work...this is what I get - "$snap.vm`t([Math]::Round($snap.SizeGB))`t($snap.Created -replace $retime)"|out-file $outfile Output 20121001.vm ([Math]::Round(20121001.Si... See more...
I tried but didn't work...this is what I get - "$snap.vm`t([Math]::Round($snap.SizeGB))`t($snap.Created -replace $retime)"|out-file $outfile Output 20121001.vm ([Math]::Round(20121001.SizeGB)) (20121001.Created -replace \d{1,2}:\d{1,2}:\d{1,2}.*?$)
write-output Hostname`tSizeGB`tCreatedOn > $outfile write-output --------`t------`t----------- >> $outfile foreach ( $snap in $snapshots ) {      if ( $snap.Created -lt (Get-Date).AddDays( -$Ag... See more...
write-output Hostname`tSizeGB`tCreatedOn > $outfile write-output --------`t------`t----------- >> $outfile foreach ( $snap in $snapshots ) {      if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) ) {      write-output $snap.vm`t([Math]::Round($snap.SizeGB))`t($snap.Created -replace $retime) >> $outfile      $count++      } } Expected output - AP       7       10/1/2012 BA      20      9/20/2012 AP      17      10/1/2012 If I use write-output and out-file, I cannot retain the format Hostname      SizeGB      CreatedOn --------      ------      ----------- Name                 PowerState Num CPUs MemoryGB       ----                 ---------- -------- --------       AP           PoweredOn  4        32.000         7 10/1/2012 Name                 PowerState Num CPUs MemoryGB       ----                 ---------- -------- --------       BA          PoweredOn  4        8.000          20 9/20/2012 Name                 PowerState Num CPUs MemoryGB       ----                 ---------- -------- --------       AP           PoweredOn  4        32.000         17 10/1/2012