PowerShell: Quick Snippet to Purge All ‘Orphaned’ Records of Resources in VMM

The Commands:

# How to purge all erroneous records of resources from the VMM Library

# ISOs
Get-SCISO | where {$_.State -eq "missing"} | Remove-SCISO

# Custom Scripts
Get-SCScript | where {$_.State -eq "missing"} | Remove-SCScript

# Drivers
Get-SCDriverPackage | where {$_.State -eq "missing"} | Remove-SCDriverPackage

# Applications
Get-SCApplicationPackage | where {$_.State -eq "missing"} | Remove-SCApplicationPackage

# Custom Resources
Get-SCCustomResource | where {$_.State -eq "missing"} | Remove-SCCustomResource

# Virtual Disks
Get-SCVirtualHardDisk | where {$_.State -eq "missing"} | Remove-SCVirtualHardDisk

Sample Outputs:

PS C:\Windows\system32> Get-SCISO | where {$_.State -eq "missing"} | Remove-SCISO
Release               :
State                 : Missing
LibraryShareId        : 00000000-0000-0000-0000-000000000000
SharePath             : C:\Windows\system32\vmguest.iso
FileShare             :
Directory             : C:\Windows\system32
Size                  : 0
IsOrphaned            : False
FamilyName            :
Namespace             :
ReleaseTime           :
HostVolumeId          :
HostVolume            :
Classification        :
HostId                : 
HostType              : VMHost
HostName              : hv1.intranet.kimconnect.com
VMHost                : hv1.intranet.kimconnect.com
LibraryServer         :
CloudId               :
Cloud                 :
LibraryGroup          :
GrantedToList         : {}
UserRoleID            : 00000000-0000-0000-0000-000000000000
UserRole              :
Owner                 :
ObjectType            : ISO
Accessibility         : Public
Name                  : vmguest
IsViewOnly            : False
Description           :
AddedTime             : 7/22/1920 9:04:52 AM
ModifiedTime          : 7/22/1920 9:04:52 AM
Enabled               : True
MostRecentTask        :
ServerConnection      : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection
ID                    : 862c2f67-4c2c-4588-8a4f-16ed3c64366f
MarkedForDeletion     : True
IsFullyCached         : True
MostRecentTaskIfLocal :

### Truncated similar outputs ### 

# Checking custom resources
PS C:\Windows\system32> Get-SCCustomResource|select name
Name
----
SAV_x86_en-US_4.9.305.198.cr
WebDeploy_x86_en-US_3.1237.1764.cr
WebDeploy_x64_en-US_3.1237.1764.cr
SAV_x64_en-US_4.9.305.198.cr

Leave a Reply

Your email address will not be published. Required fields are marked *