-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget Zombie vmdk file.TXT
59 lines (54 loc) · 1.72 KB
/
get Zombie vmdk file.TXT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# Purpose : List all orphaned vmdk on all datastores in all VC's
# Version: 1.0
# Author : HJA van Bokhoven
#Main
#$arrayVC = "YourVirtualCenter"
$OutputFile = "D:\temp\OrphanedVMDK.txt"
#Foreach ($strVC in $arrayVC)
#{
#Connect-VIServer $strVC
#$arrUsedDisks = Get-VM | Get-HardDisk | %{$_.filename}
#$arrDS = Get-Datastore
#Foreach ($strDatastore in $arrDS)
#{
# $strDatastoreName = $strDatastore.name
#Write-Host $strDatastoreName
$ds = Get-Datastore -Name "VA1_SQL_NONPROD_001_004" | %{Get-View $_.Id}
$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
$fileQueryFlags.FileSize = $true
$fileQueryFlags.FileType = $true
$fileQueryFlags.Modification = $true
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec.details = $fileQueryFlags
$searchSpec.sortFoldersFirst = $true
$dsBrowser = Get-View $ds.browser
$rootPath = "["+$ds.summary.Name+"]"
$searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
$myCol = @()
foreach ($folder in $searchResult)
{
foreach ($fileResult in $folder.File)
{
$file = "" | select Name, FullPath
$file.Name = $fileResult.Path
$strFilename = $file.Name
IF ($strFilename)
{
{
IF (!$strFilename.Contains("-flat.vmdk"))
{
$strCheckfile = "*"+$file.Name+"*"
IF ($arrUsedDisks -Like $strCheckfile){}
ELSE
{
$strOutput = $strDatastoreName + " Orphaned VMDK Found: " + $strFilename
$strOutput | Out-File $Outputfile -width 150 -Append
}
}
}
}
}
}
# }
#}