Posted in
Virtual Machine Manager,
Windows Powershell |
No Comment | 1,606 views | 01/04/2014 10:41
You can search a VM directory in Cluster Shared Volumes (CSV) with following script:
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
| # VM Name
$VMName = "VM Test"
# Get Cluster Nodes
$ClusterNodes = "vmhost01.domain.com","vmhost12.domain.com"
foreach ($ClusterNode in $ClusterNodes)
{
$Volumes = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\
foreach ($Volume in $Volumes)
{
$ConfigFolders = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\$Volume
foreach ($ConfigFolder in $ConfigFolders)
{
$Result = "0";
Write-Host $ConfigFolder
if ($ConfigFolder -like "*$VMName*")
{
Write-Host " "
Write-Warning "VMName: $VMName"
Write-Warning "Volume: $Volume"
Write-Warning "VMHost: $ClusterNode"
Write-Host " "
}
}
}
} |
# VM Name
$VMName = "VM Test"
# Get Cluster Nodes
$ClusterNodes = "vmhost01.domain.com","vmhost12.domain.com"
foreach ($ClusterNode in $ClusterNodes)
{
$Volumes = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\
foreach ($Volume in $Volumes)
{
$ConfigFolders = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\$Volume
foreach ($ConfigFolder in $ConfigFolders)
{
$Result = "0";
Write-Host $ConfigFolder
if ($ConfigFolder -like "*$VMName*")
{
Write-Host " "
Write-Warning "VMName: $VMName"
Write-Warning "Volume: $Volume"
Write-Warning "VMHost: $ClusterNode"
Write-Host " "
}
}
}
}
This script requires at least PowerShell v3 to work.