Skip to content

Instantly share code, notes, and snippets.

@BenNeise
Created October 29, 2013 12:17
Show Gist options
  • Save BenNeise/7213597 to your computer and use it in GitHub Desktop.
Save BenNeise/7213597 to your computer and use it in GitHub Desktop.
# Set up an empty array
$arrTemplatesWithPersistentDrives = @()
# Get all the template objects
$objTemplates = Get-Template
# Loop through each template
ForEach ($objTemplate in $objTemplates){
# Get the drives associated with that template
$objHardDisks = $objTemplate | Get-HardDisk
# Loop through each drive
ForEach ($objHardDisk in $objHardDisks){
# If any of the drives are non-persistent, add the template object to the empty array
If ($objHardDisk.Persistence -match "non"){
$arrTemplatesWithPersistentDrives += $objTemplate
}
}
}
# List the names of the unique templates in the array (as a template with more than one non-perisistent drive would appear more than once)
$arrTemplatesWithPersistentDrives | Sort-Object -Unique | Select-Object Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment