vmCalgary's Posts

Perfection. Thanks for your help.
Not entirely. The second line was missing the closing bracket and the cluster information was missing. This is to be used as part of a lifecycle replacement project.
I found this on one of your replies, LucD. I don't really need the details for each vmhost  as per cluster was good enough. I guess I didn't do enough sleuthing before I posted.   Get-Datacenter -... See more...
I found this on one of your replies, LucD. I don't really need the details for each vmhost  as per cluster was good enough. I guess I didn't do enough sleuthing before I posted.   Get-Datacenter -PipelineVariable dc | Get-Cluster -PipelineVariable cluster | Get-VMHost | Get-VirtualPortGroup |   Select @{N = 'Datacenter'; E = {$dc.Name}},    @{N = 'Cluster'; E = {$cluster.Name}},   Name, VlanId,    @{N = 'VMCount'; E = {($_ | Get-VM).Count}} | Group-Object -Property Datacenter, Cluster, Name | ForEach-Object -Process {    $_ | Select @{N = 'Datacenter'; E = {$_.Name.Split(',')[0].Trim(' ')}},    @{N = 'Cluster'; E = {$_.Name.Split(',')[1].Trim(' ')}},    @{N = 'Portgroup'; E = {$_.Name.Split(',')[2].Trim(' ')}},    @{N = 'VlanId'; E = {$_.Group[0].VlanId}},    @{N = 'VMHostCount'; E = {$_.Count}},    @{N = 'VMCount'; E = {($_.Group | Measure-Object -Property VMCount -Sum).Sum}} }
I am looking for some help gathering a list of portgroups and vlans by cluster & vmhost. Desired column headers: Cluster VMhost Portgroup vlan vcenter Counts of VMs and VMHosts per cluster is ... See more...
I am looking for some help gathering a list of portgroups and vlans by cluster & vmhost. Desired column headers: Cluster VMhost Portgroup vlan vcenter Counts of VMs and VMHosts per cluster is a 'would be nice' to have as well.  
Does anyone have a one or two liner to identify templates that are using thick provisioned hard disks?
I have a list of vms, which can be stored in either csv or txt, where I want to snoop the guest os for any nfs mounts and gather a report that says:   VM name        NFS Mount path   Is this poss... See more...
I have a list of vms, which can be stored in either csv or txt, where I want to snoop the guest os for any nfs mounts and gather a report that says:   VM name        NFS Mount path   Is this possible to do with powercli?
I'm going to let Excel do some heavy lifting. I'll use out-file and send to txt. Then copy and paste into excel and use the 'convert text to columns' feature. Final code (for now):   $vmList =... See more...
I'm going to let Excel do some heavy lifting. I'll use out-file and send to txt. Then copy and paste into excel and use the 'convert text to columns' feature. Final code (for now):   $vmList = Get-Content C:\users\jmamer\VMware_scripts\SpringCleaning\PoweredOff\all-Nov10.txt # list VMs in txt file $report = @() foreach ($vmName in $vmList) {Get-VM -Name $vmName -PipelineVariable vm | ForEach-Object -Process { $vmxPath = $vm.ExtensionData.Config.Files.VmpathName $dsObj = Get-Datastore -Name $vmxPath.Split(']')[0].TrimStart('[') New-PSDrive -Location $dsObj -Name DS -PSProvider VimDatastore -Root "\" | Out-Null $tempFile = [System.IO.Path]::GetTempFileName() Copy-DatastoreItem -Item "DS:\$($vm.Name)\vmware.log" -Destination $tempFile Get-Content -Path $tempFile | where {$_ -match 'VMX has left the building|CPU reset:|power|Power|vmotion|Vmotion' } | ForEach-Object -Process { $fields = $_.Split('|') New-Object -TypeName PSObject -Property @{ VM = $vm.Name Timestamp = [DateTime]$fields[0] Row = $fields } } Remove-Item -Path $tempFile -Confirm:$false Remove-PSDrive -Name DS -Confirm:$false } | Select-Object VM,Timestamp,Row }   I'll run a function in Excel to see which VMs are missing (no vmware.log). It could be prettier but I need to get to the analysis part of the problem I'm working on with reclaiming resources. Thanks so much Luc.
Thank you (as always) Luc. Works much better.   Copy-DatastoreItem : 11/10/2021 2:41:01 PM Copy-DatastoreItem Cannot find path 'DS:\TAM_Data_collector.sjrb.ad\vmware.log' because ... See more...
Thank you (as always) Luc. Works much better.   Copy-DatastoreItem : 11/10/2021 2:41:01 PM Copy-DatastoreItem Cannot find path 'DS:\TAM_Data_collector.sjrb.ad\vmware.log' because it does not exist. At C:\users\jmamer\VMware_scripts\SpringCleaning\PoweredOff\VMX-left-the-building.ps1:27 char:5 + Copy-DatastoreItem -Item "DS:\$($vm.Name)\vmware.log" -Destinatio ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (System.Object[]:Object[]) [Copy-DatastoreItem], VimException + FullyQualifiedErrorId : Core_CopyDatastoreItem_TryValidateSourceItem_InvalidSourceItem,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyD atastoreItem   I get this is because the script couldn't find a vmware.log file, often the case if the VM has never been powered up, but how do i get a log file of  VM names where vmware.log could not be read? When I export-csv, the output looks like: When I run on the command line it looks like this: Why? Joy PS. I'll use Excel to calculate duration.
@LucD wrote: I'm not sure why you split each line on a vertical bar, in the example lines I don't see any I wasn't sure what that line was doing in the original code. VMware.log looks like t... See more...
@LucD wrote: I'm not sure why you split each line on a vertical bar, in the example lines I don't see any I wasn't sure what that line was doing in the original code. VMware.log looks like this, as you well know. 2021-11-04T17:16:28.362Z| vmx| I125: Vix: [956803 mainDispatch.c:4253]: VMAutomation: Ignoring ReportPowerOpFinished because the VMX is shutting down. 2021-11-04T17:16:28.362Z| vmx| I125: Transitioned vmx/execState/val to poweredOff 2021-11-04T17:16:28.362Z| vmx| I125: Vigor_ClientRequestCb: failed to do op=5 on unregistered device 'ConfigParams' (cmd=(null)) 2021-11-04T17:16:28.362Z| vmx| I125: VMX idle exit 2021-11-04T17:16:28.378Z| vmx| I125: Vix: [956803 mainDispatch.c:834]: VMAutomation_LateShutdown() 2021-11-04T17:16:28.378Z| vmx| I125: Vix: [956803 mainDispatch.c:783]: VMAutomationCloseListenerSocket. Closing listener socket. 2021-11-04T17:16:28.380Z| vmx| I125: Flushing VMX VMDB connections 2021-11-04T17:16:28.380Z| vmx| I125: VigorTransport_ServerCloseClient: Closing transport 1CB4529850 (err = 0) 2021-11-04T17:16:28.380Z| vmx| I125: VigorTransport_ServerDestroy: server destroyed. 2021-11-04T17:16:28.380Z| vmx| I125: VMX exit (0). 2021-11-04T17:16:28.381Z| vmx| I125: AIOMGR-S : stat o=153 r=308 w=59 i=125 br=4458660 bw=338807 2021-11-04T17:16:28.381Z| vmx| I125: AIOMGR-U : stat o=14 r=12 w=127 i=0 br=96 bw=214512 2021-11-04T17:16:28.381Z| vmx| I125: OBJLIB-LIB: ObjLib cleanup done. 2021-11-04T17:16:28.381Z| vmx| W115: VMX has left the building: 0.  I'll focus on what I want to get from the log. I want timestamp and the message. Timestamp VMX has left the building: 0. Transitioned vmx/execState/val to poweredOff VMX exit (0). Is this how I'd write my regex? Get-Content -Path $tempFile | where {$_ -match 'VMX has left the building'|'CPU reset:'|'power|'Power'|'vmotion'|'Vmotion' } |
@LucD, The script was attached. I guess I should have mentioned that. Turns out my Row variable didn't work well. $vmList = Get-Content C:\users\jm\VMware_scripts\SpringCleaning\PoweredOff\all-Nov1... See more...
@LucD, The script was attached. I guess I should have mentioned that. Turns out my Row variable didn't work well. $vmList = Get-Content C:\users\jm\VMware_scripts\SpringCleaning\PoweredOff\all-Nov10.txt # list VMs in txt file $report = @() foreach ($vmName in $vmList) {Get-VM -Name $vmName -PipelineVariable vm | ForEach-Object -Process { $vmxPath = $vm.ExtensionData.Config.Files.VmpathName $dsObj = Get-Datastore -Name $vmxPath.Split(']')[0].TrimStart('[') New-PSDrive -Location $dsObj -Name DS -PSProvider VimDatastore -Root "\" | Out-Null $tempFile = [System.IO.Path]::GetTempFileName() Copy-DatastoreItem -Item "DS:\$($vm.Name)\vmware.log" -Destination $tempFile Get-Content -Path $tempFile | where {($_ -match 'VMX has left the building' -or $_ -match 'CPU reset:')} | ForEach-Object -Process { $fields = $_.Split('|') New-Object -TypeName PSObject -Property @{ VM = $vm.Name Timestamp = [DateTime]$fields[0] CPU = $fields[1].Trim(' ') Duration = $fields[2].Split(' ')[6] Row = $fields } } Remove-Item -Path $tempFile -Confirm:$false Remove-PSDrive -Name DS -Confirm:$false } | Select-Object VM,Timestamp,Duration,Row }  
https://kb.vmware.com/s/article/1019064 taught me quite a bit about what logs in vmware.log for power-down of a machine.I knew about "VMX has left the building" for power down and vmotions. The KB ta... See more...
https://kb.vmware.com/s/article/1019064 taught me quite a bit about what logs in vmware.log for power-down of a machine.I knew about "VMX has left the building" for power down and vmotions. The KB taught me a few others. See attached code which has been plagiarized from a stun time script. This will be used to confirm VMs have indeed been powered off for greater than 90 days. The last time I did this exercise users claimed they powered on their VMs since the date I stated the VM was powered off. This time, I'm gathering my evidence first. 1) I'm not strong (yet) in regex. I want to search vmware.log for the following strings.  I'm not sure how to do multiple (greater than 2) or statements. VMX has left the building CPU reset Power power vmotion 2) What is this line of code doing: Duration = $fields[2].Split(' ')[6]    It doesn't give me a duration in days, but something like this (note: the following is a paste from the export-csv output and is a cell). I added the variable Row as that's more useful to me but still want to learn from the plagiarized code. building:   VM Timestamp Duration Row -- --------- -------- --- TAM_Health_Amalyzer-5.5.4 11/4/2021 11:26:27 AM 2) {2021-11-04T17:26:27.845Z, vcpu-0, I125: CPU reset: hard... TAM_Health_Amalyzer-5.5.4 11/4/2021 12:29:08 PM building: {2021-11-04T18:29:08.516Z, vmx, W115: VMX has left the b...    
I'm looking for an efficient method of executing the following: Make a variable ($vms) that is: VMs where snapshot name is not like "_GX_BACKUP_" or VM tag name is not "Keep Snaphot" and snapshot is... See more...
I'm looking for an efficient method of executing the following: Make a variable ($vms) that is: VMs where snapshot name is not like "_GX_BACKUP_" or VM tag name is not "Keep Snaphot" and snapshot is older than 3 days. I then want to report on what is going to be deleted to a csv (name of vm, vcenter, snapshot name, size, creator, age). Then I want the snapshots deleted.   Our users in our lab env are keeping snapshots to go back and forth with vendors on projects and the 3 days best practices interferes with their projects. We also want to investigate why the backup tools didn't auto delete the GX_BACKUP snapshots.   I'll be testing this then scheduling it according to http://www.virtu-al.net/2009/07/10/running-a-powercli-scheduled-task/.
@LucD    Is this still valid syntax for reporting on deleted snapshots? I'd like to add who deleted the snapshot and what was the snapshot size.
Is there a way to combine vrops metrics of snapshot size into this script? Vrealize will have the five minute stats on snapshot size. 
Thanks Luc. I will use filters in excel when I export to csv.
How do I get the stun time for a particular date? vmware.log contains multiple stun times and I only care about the times greater than  Oct 28 6pm to Oct 29 2am?
  Which "Get-VM | gm" option gives me the storage usage I see on the VM summary page?
$ds  = Get-Datastore -Name $ds | where {($_.Name -notlike "st074no_templates_ds01") -and ($_.Name -notlike "st004no_templates_ds1-q1" ) -and ($_.Name -notcontains local)}   I want to exclude: st007... See more...
$ds  = Get-Datastore -Name $ds | where {($_.Name -notlike "st074no_templates_ds01") -and ($_.Name -notlike "st004no_templates_ds1-q1" ) -and ($_.Name -notcontains local)}   I want to exclude: st0074no_templates_ds01, st004no_templates_ds-q1, and all datastores that contain 'local' in the name.   What is the syntax? Thank you in advance.
A VM was powered off last year. I want to use powercli or vrops to find out who powered it off. VIEvent is not helpful, I think, as we are past the time events are kept. Suggestions welcomed.
LucD, I read through the comments in your spring cleaning script. I admit it, I got lost when it came to altering the script for an NFS environment. Do you have a copy of your script that returns r... See more...
LucD, I read through the comments in your spring cleaning script. I admit it, I got lost when it came to altering the script for an NFS environment. Do you have a copy of your script that returns results for an NFS environment?