-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllControllerVolumeListing.ps1
More file actions
154 lines (128 loc) · 5.67 KB
/
Copy pathAllControllerVolumeListing.ps1
File metadata and controls
154 lines (128 loc) · 5.67 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<#
.SYNOPSIS
Script collects all the root level objects from all controllers' all volume in the environment
Tested on
PowerShell version 5.0
Netapp Powershell Toolkit v4.4
.DESCRIPTION
Requires 3 list of filers named "filers", "AdministratorFilers", and "123Filers"
in the folder "Z:\Storage\VM_SNAP_RECOVERY_PROCEDURE\scripts\NDMP Toolkit\FilerLists"
The output is a file named after the filer, and contains volume name and objectum name devided by colon.
vctv610a_c262_vm_01:usctapp41069
vctv610a_c262_vm_01:usctapp41072
vctv610a_c262_vm_01:usctapt10978
.PARAMETER
The script does not use any parameters
.INPUTS
None
.OUTPUTS
Files that contain the volume and the object names
.NOTES
Version: 1.0
Author: gergely.laszlo@cognizant.com
kevin.ayer@cognizant.com
Creation Date: August 15, 2017
Change Date: August 31, 2017
Purpose/Change:
.EXAMPLE
From the PowerShell console window:
PS D:\Scripts> .\AllControllerVolumeListing.ps1
From the Windows command prompt:
D:\Scripts>Powershell.exe -Executionpolicy RemoteSigned -File D:\Scripts\AllControllerVolumeListing.ps1
#>
#----- Initialisations -----
<# Attempt to import the Netapp required module and exit the script if it fails
This module is required to run the ndmpcopy. No need to continue if loading it fails #>
try
{
Import-Module DataONTAP
}
catch
{
Write-Host "Error loading module, aborting script..."
write-host $error[0].Exception -ForegroundColor Red
Exit 10
}
# Log file
$VolListLog = "Z:\Storage\VM_SNAP_RECOVERY_PROCEDURE\scripts\NDMP Toolkit\log\VolObjErr.log"
# Location of filer lists
$ListContainer = "Z:\Storage\VM_SNAP_RECOVERY_PROCEDURE\scripts\NDMP Toolkit\FilerLists"
#------ Function Defintions ---------
# Function to set the credentials for the given filer. UID/PWD differs regarding the type of filer
Function Set-MerckCredentials ($UserID, $Password) {
#Write-Host "$UserID"
#Write-Host "$Password"
$ssPassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$myCredential = New-Object System.Management.Automation.PSCredential $UserID,$ssPassword
Return $myCredential
} # End of Function Set-MerckCredentials
# Function is to collect the top level objects from all volume of all the filers in the current type
Function Get-TopLevelObjects ($myLog) {
$myDestinationDir="Z:\Storage\VM_SNAP_RECOVERY_PROCEDURE\AllControllersVolumeListingPowerShell"
# Getting the source information
foreach ($filer in $myFilers){
Write-Host "Started working on the filer $filer..."
Remove-Item $ENV:TEMP\$filer -ErrorAction silentlycontinue
$HostData = [System.Net.Dns]::GetHostAddresses($filer)[0]
$HostIP = $HostData.IPAddressToString
# connect to the filer
try {
$myConnectedFiler = Connect-NaController -Name $HostIP -Credential $Credential -HTTP
}
catch {
"There was an issue connecting to $filer filer" | Tee-Object $myLog -Append
Continue
}
try {
$myVols = Get-NaVol | ?{$_.state -eq "online"} | Select-String .* | Select-String vol0 -notmatch
}
catch {
"There was an issue getting the directories from $filer filer" | Tee-Object $myLog -Append
Continue
}
foreach ($vol in $myVols) {
Write-Host "$vol"
try {
$myObjects=Read-NaDirectory -path /vol/$vol | Select-String .* | Select-String \.$ -notmatch
}
catch {
"There was an issue reading directory /vol/$vol from $filer filer" | Tee-Object $myLog -Append
Continue
}
foreach ($object in $myObjects){
#Write-Host "$vol`:$object"
Add-Content $ENV:TEMP\$filer "$vol`:$object"
}
}
try {
Copy-Item $ENV:TEMP\$filer $myDestinationDir\$filer
}
catch {
"There was an issue copying the file $filer to Z: drive" | Tee-Object $myLog -Append
}
Write-Host ""
}
} # End of Function Get-TopLevelObjects
# ----- End of Function Definitions -----
# ----- Begin body. Script execution begins here --------------
$startTime=Get-Date
"Script started at $startTime" | Tee-Object $VolListLog -Append
$myFilers=Get-Content $ListContainer\filers
$Credential = Set-MerckCredentials "root" "L3tm31n!" #Get-Credential -Message "Password for the `"root`" filers" -UserName root
Get-TopLevelObjects $VolListLog
$myFilers=Get-Content $ListContainer\123Filers
$Credential = Set-MerckCredentials "root" "netapp132" # Get-Credential -MessagePassword "Password for the 123 filers" -UserName root
Get-TopLevelObjects $VolListLog
$myFilers=Get-Content $ListContainer\AdministratorFilers
$Credential = Set-MerckCredentials "Administrator" "L3tm31n!" # Get-Credential -Message "Password for the Admin filers" -UserName Administrator
Get-TopLevelObjects $VolListLog
$endTime=Get-Date
"Script finished running at $endTime" | Tee-Object $VolListLog -Append
<# Change Log
0. Initial version by Geri. 08/14/2017
Originally it was written in cygwin/bash. I realized that in some strange cases the controller does not give back the correct list of "ls" command to the command line. There were missing folders, so I decicded to rewrite the collection using the NetApp PowerShell Toolkit.
1. Kevinization of the script. Geri 08/31/2017
Talked to Kevin Ayers today, he showed how he writes scripts. I wanted to standardize our scripts, so I reformatted the script.
2. Moved the script from local machine to "Z drive". Geri 08/31/2017
Originally I placed the script on my notebook. As it did not show any issues, I moved it to the network drive. That meant it is running, or can run directly from the network, so I had to ensure the temp files are written locally, otherwise the runtime would be much longer. Also, it reads the filer lists from the network drive.
#>