What I am trying to do is get a list of VM Snapshots but exclude any snapshots that contain the VM naming convention of "ABCDE" and that the snapshots are over 3 days old and output it to a text file.
The script that I have thus far is the following but it is not excluding the servers that begin with "ABCDE".
# Get VM Snapshot Information excluding anything with HEIEPC
Get-VM | Where {$_.Name -ne "ABCDE"} |
Get-Snapshot |
Where-Object { $_.Created -lt (Get-Date).AddDays(-3) } |
Format-List | Out-File $Log -Append
You're checking for VMs with the exact name "ABCDE". To check for VMs whose name begins with "ABCDE" use the -like
operator and a wildcard:
Get-VM | Where { $_.Name -notlike 'ABCDE*' } | ...
Make the pattern *ABCDE*
if you want to exclude VMs with the substring "ABCDE" anywhere in their name (not just the beginning).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.