-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathfindsrmVMs.ps1
61 lines (57 loc) · 3.26 KB
/
findsrmVMs.ps1
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
60
61
#Enter the following parameters. Put all entries inside the quotes:
#**********************************
$vcenter = "vCenter Address"
$vcuser = "username"
$vcpass = "password"
$logfolder = "C:\Users\user\Documents\Results\"
#############################
set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false |out-null
If (!(Test-Path -Path $logfolder)) { New-Item -ItemType Directory -Path $logfolder }
$logfile = $logfolder + (Get-Date -Format o |ForEach-Object {$_ -Replace ":", "."}) + "SRMProtectedVMs.txt"
add-content $logfile " __________________________"
add-content $logfile " /++++++++++++++++++++++++++\"
add-content $logfile " /++++++++++++++++++++++++++++\"
add-content $logfile " /++++++++++++++++++++++++++++++\"
add-content $logfile " /++++++++++++++++++++++++++++++++\"
add-content $logfile " /++++++++++++++++++++++++++++++++++\"
add-content $logfile " /++++++++++++/----------\++++++++++++\"
add-content $logfile " /++++++++++++/ \++++++++++++\"
add-content $logfile " /++++++++++++/ \++++++++++++\"
add-content $logfile " /++++++++++++/ \++++++++++++\"
add-content $logfile " /++++++++++++/ \++++++++++++\"
add-content $logfile " \++++++++++++\ /++++++++++++/"
add-content $logfile " \++++++++++++\ /++++++++++++/"
add-content $logfile " \++++++++++++\ /++++++++++++/"
add-content $logfile " \++++++++++++\ /++++++++++++/"
add-content $logfile " \++++++++++++\ /++++++++++++/"
add-content $logfile " \++++++++++++\"
add-content $logfile " \++++++++++++\"
add-content $logfile " \++++++++++++\"
add-content $logfile " \++++++++++++\"
add-content $logfile " \------------\"
add-content $logfile ""
add-content $logfile "Pure Storage SRM Protected VM Inquiry Script"
add-content $logfile "----------------------------------------------"
add-content $logfile ""
connect-viserver -Server $vcenter -username $vcuser -password $vcpass|out-null
Connect-SrmServer |out-null
$srmapi = $defaultsrmservers.ExtensionData
$srmpgs = $srmapi.protection.listprotectiongroups()
for ($i=0; $i -lt $srmpgs.Count; $i++)
{
$vms = $srmpgs[$i].ListProtectedVMs()
$pgvms = [array] "Virtual Machine list:"
for ($a=0; $a -lt $vms.Count; $a++)
{
$vm = get-vm -ID $vms[$a].VM.MoRef
$pgvms += $vm.Name
}
$pgname = $srmapi.protection.listprotectiongroups()[$i].GetInfo().Name
add-content $logfile "==================================================================================="
add-content $logfile "******************************Next Protection Group********************************"
add-content $logfile "==================================================================================="
$text = "The following " + $vms.Count + " virtual machines are in the Protection Group named " + $pgname
add-content $logfile $text
add-content $logfile $pgvms
}
disconnect-viserver -Server $vcenter -confirm:$false