forked from DeploymentBunny/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e77903
commit 4f274cb
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Function Get-VIADisconnectedVHDs | ||
{ | ||
<# | ||
.Synopsis | ||
Script used find .VHD files that are not connected to VM's | ||
.DESCRIPTION | ||
Created: 2016-11-07 | ||
Version: 1.0 | ||
Author : Mikael Nystrom | ||
Twitter: @mikael_nystrom | ||
Blog : http://deploymentbunny.com | ||
Disclaimer: This script is provided "AS IS" with no warranties. | ||
.EXAMPLE | ||
Get-Get-VIADisconnectedVHDs | ||
#> | ||
[CmdletBinding(SupportsShouldProcess=$true)] | ||
|
||
Param( | ||
[string]$Folder | ||
) | ||
|
||
if((Test-Path -Path $Folder) -ne $true){ | ||
Write-Warning "I'm sorry, that folder does not exist" | ||
Break | ||
} | ||
|
||
#Get the disk used by a VM | ||
$VMs = (Get-VM | Where-Object -Property ParentSnapshotName -EQ -Value $null).VMId | ||
|
||
if(($VMs.count) -eq '0'){ | ||
Write-Information "Sorry, could not find any VM's" | ||
Break | ||
} | ||
$VHDsActive = foreach($VMsID in $VMs){ | ||
Get-VMHardDiskDrive -VM (Get-VM -Id $VMsID) | ||
} | ||
|
||
#Get the disk in the folder | ||
$VHDsAll = Get-ChildItem -Path $Folder -Filter *.vhd* -Recurse | ||
if(($VHDsAll.count) -eq '0'){ | ||
Write-Information "Sorry, could not find any VHD's in $folder" | ||
Break | ||
} | ||
|
||
$obj = Compare-Object -ReferenceObject $VHDsActive.Path -DifferenceObject $VHDsAll.FullName | ||
|
||
#Compare and give back the list of .vhd's that are not connected | ||
Return ($obj | Where-Object -Property SideIndicator -EQ -Value =>).InputObject | ||
} |