From 8cecbed0719620e81c3d730659bfb8b04b613ebe Mon Sep 17 00:00:00 2001 From: Timur Date: Fri, 21 Jun 2024 10:59:26 +0000 Subject: [PATCH] VMware.Snapshot-CDdrive.check Check for VM in Cluster with subfolder incl. is there any Snapshop or CDdrive mounted --- VMware.Snapshot-CDdrive.check | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 VMware.Snapshot-CDdrive.check diff --git a/VMware.Snapshot-CDdrive.check b/VMware.Snapshot-CDdrive.check new file mode 100644 index 0000000..3be44ad --- /dev/null +++ b/VMware.Snapshot-CDdrive.check @@ -0,0 +1,56 @@ +Import-Module VMware.VimAutomation.Core +Set-PowerCLIConfiguration -InvalidCertificateAction Prompt -Confirm:$false + +# Verbindung vCenter +Connect-VIServer -Server "SERVER" -User "administrator@vsphere.local" -Password "PASSWORD" + + +$clusterName = "CLUSTER" +$folderName = "FOLDER" + +# Get the cluster object +$cluster = Get-Cluster -Name $clusterName + +# Get the folder object recursively +$folder = Get-Folder -Name $folderName -Location (Get-Folder -NoRecursion | Where-Object { $_.Name -eq $folderName }) + +# Get all VMs in the specified folder and its subfolders that are on hosts in the specified cluster +$vms = Get-VM -Location $folder | Where-Object { $_.VMHost.Parent -eq $cluster } + +# Check jede VM und prüfe die CD/DVD-Laufwerke und Snapshots +foreach ($vm in $vms) { + $cdDrives = Get-CDDrive -VM $vm + $snapshots = Get-Snapshot -VM $vm -ErrorAction SilentlyContinue + + # Prüfe, ob ein verbundenes CD/DVD-Laufwerk vorhanden ist + $cdDriveConnected = $false + foreach ($cdDrive in $cdDrives) { + if ($cdDrive.ConnectionState.Connected) { + $cdDriveConnected = $true + break + } + } + + # Prüfe, ob Snapshots vorhanden sind + $snapshotExists = $false + if ($snapshots) { + $snapshotExists = $true + } + + # Füge das Ergebnis zur Liste hinzu + $results += [PSCustomObject]@{ + VMName = $vm.Name + CDDriveConnected = $cdDriveConnected + SnapshotExists = $snapshotExists + } +} + +# Generiere einen Dateinamen mit aktuellem Datum und Uhrzeit +$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" +$filepath = "C:\Users\DeineMuddaTV\Desktop\Output\Snapshot-and-CD-Check_$timestamp.csv" + +# Exportiere die Ergebnisse in eine CSV-Datei +$results | Export-Csv -Path $filepath -NoTypeInformation + +# Trenne die Verbindung zum vCenter-Server +Disconnect-VIServer -Confirm:$false \ No newline at end of file