Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

60 Powered Off VMs #765

Open
gcoxpwpartnerscom opened this issue Jan 27, 2025 · 1 comment
Open

60 Powered Off VMs #765

gcoxpwpartnerscom opened this issue Jan 27, 2025 · 1 comment

Comments

@gcoxpwpartnerscom
Copy link

Hi everyone, not sure if anyone tracks this stuff anymore, but thought I'd post anyway, having an issue with the 60 Powered Off VMs script, it seems to bomb out (ram just goes nuts) on the server running the script and it never completes, even if left for days. We have 2 VCs in Europe, 2 VCs in the US, the script only fails on the US ones, all VCs are the same in terms of their logging/retention levels, so I can't figure out why the script fails for the US ones. Anyone who has encountered this issue before or can help me identify where the issue is, would be greatly appreciated.

@alanrenouf
Copy link
Owner

Thats a very strange one to fail on, that script filters the already discovered information to give you an answer, maybe run the code independently in a powershell session to see whats going on? You should be able to connect a powercli session and then run:

$VM = Get-VM | Sort-Object Name

# Start of Settings 
# VMs not to report on (regex)
$IgnoredVMs = "TEMPLATE|BUILD"
# VmPathName not to report on
$IgnoredVMpath = "-backup-"
# VmFolder not to report on
$IgnoredVMFolder = "Templates"
# Report VMs powered off over this many days
$PoweredOffDays = 7
# End of Settings

# Update settings where there is an override
$IgnoredVMs = Get-vCheckSetting $Title "IgnoredVMs" $IgnoredVMs
$IgnoredVMpath = Get-vCheckSetting $Title "IgnoredVMpath" $IgnoredVMpath
$PoweredOffDays = Get-vCheckSetting $Title "PoweredOffDays" $PoweredOffDays

$VM | Where-Object {$_.ExtensionData.Config.ManagedBy.ExtensionKey -ne 'com.vmware.vcDr' -and 
                $_.PowerState -eq "PoweredOff" -and 
                $_.LastPoweredOffDate -lt $date.AddDays(-$PoweredOffDays) -and
                $_.Name -notmatch $IgnoredVMs -and 
                $_.Folder.Name -notmatch $IgnoredVMFolder -and
                $_.ExtensionData.Config.Files.VmPathName -notmatch $IgnoredVMpath} |
  Select-Object -Property Name, LastPoweredOffDate, @{l = 'Folder'; e = {$_.Folder.Name}}, Notes |
  Sort-Object -Property LastPoweredOffDate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants