-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_policy_details_csv2.ps1
152 lines (121 loc) · 12.5 KB
/
get_policy_details_csv2.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
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
#----------------------------------------------
# Name: export_to_csv_for_nw_migation
# Version: 1.0.0.0
# Start date: 9.01.2016
# Release date:
# Description:
#
# Author: George Dicu
# Department: Cloud, Backup
#----------------------------------------------
cd\
$nbpath = "C:\Program Files\Veritas\NetBackup\bin\admincmd"
#$policies = Read-Host
#$policies = Import-Csv "C:\EH tapes test\tapes.csv"
$container = @()
#function to create the array of dictionaries
function hashtable () {
$PropertyHash = @{}
$PropertyHash += @{
"policy" = $args[0]
"policy_Type" = $args[1]
"client" = $args[2]
"saveset" = $args[3]
"retention" = $args[4]
"shedule_type" = $args[5]
"daily_windows" = $args[6]
}
$container += New-Object -TypeName PSObject -Property $PropertyHash
}
if (Test-Path $nbpath) {
cd $nbpath
#hash where all data will be saved
$PolicyHash = @{}
$policies = @()
Write-Host "Please give link to policies csv file exported by export_all_polies.ps1 script"
#$pcsvpath = Read-Host
$policies = Import-Csv -Path "C:\temp\allpolicies2.csv"
foreach($policy in $policies){
#creating $pc array for all trimmed items from $policycontainer and the final container:$PolicyHash
$pc = @()
#excel index variable
$policyname = $policy | select -ExpandProperty PolicyName
$policycontainer = .\bppllist $policyname -U
if(($policy | select -ExpandProperty Active) -eq "yes"){
Write-Output "going through Policy:$policyname"
$pc = @()
#Iterating the policy items without 1st two items
foreach($item in $policycontainer[2..($policycontainer.Count)]){
#if on item is null eliminate it
if ($item.Trim() -eq ""){
continue
}
if($item -match "EXCLUDE DATE " -or $item -match "SPECIFIC DATE "){
continue
}
#recreating the array for new item in $policycontainer
$pc += $item.Trim()
}
}
#///////////////////////////////////////////////////////////////////////
#GET CLIENTS
#///////////////////////////////////////////////////////////////////////
#once we have the policy detail without any spaces or uneccessary details we get the clients:
$clients = $pc[([array]::IndexOf($pc,($pc -match "HW/OS/Client:")[0]))..(([array]::IndexOf($pc,($pc -match "Include:")[0]))-1)]
$clients[0] = $clients[0].substring(14).trim()
$hostnames = @()
$architecture = @()
$os = @()
foreach($client in $clients){
$architecture += ($client -replace "\s+",";").split(";")[0]
$hostnames += ($client -replace "\s+",";").split(";")[2]
$os += ($client -replace "\s+",";").split(";")[1]
}
#///////////////////////////////////////////////////////////////////////
#GET POLICY AND POLICY DETAIL
#///////////////////////////////////////////////////////////////////////
#saveing all items that could be relevant for migration
$matches = ("Policy Name","Policy Type","Active","File Restore Raw","Mult. Data Streams",
"Client Encrypt","Checkpoint","Policy Priority","Max Jobs/Policy","Disaster Recovery",
"Collect BMR info","Keyword","Data Classification","Application Discovery","Discovery Lifetime",
"ASC Application and attributes","Granular Restore Info","Ignore Client Direct","Client Compress",
"Enable Metadata Indexing","Index server name","Use Accelerator","Collect TIR info",
"File Restore Raw","Interval","Optimized Backup","Application Consistent","Block Incremental",
"Cross Mount Points","Follow NFS Mounts","Exchange DAG Preferred Server","Exchange Source passive db if available")
#policyname and type can be obtain from $policy variable
$pn = $policy | select -ExpandProperty PolicyName
$pt = $policy | select -ExpandProperty PolicyType
#///////////////////////////////////////////////////////////////////////
#GET SAVESETS/SELECTIONS
#///////////////////////////////////////////////////////////////////////
#Include Column/Property has different aspects for different policy types
#getting index interval from Include Column to 1st Schedule-1 where resided last Include item
$allincludes = $pc[([array]::IndexOf($pc,($pc -match "Include:")[0]))..(([array]::IndexOf($pc,($pc -match "Schedule:")[0]))-1)]
#1st element has Include: before it`s begining, removing it
$allincludes[0] = $allincludes[0].substring(8).trim()
foreach ($include in $allincludes) {
if($include -eq "NEW_STREAM"){
continue
}
$allincludes += $include
}
#///////////////////////////////////////////////////////////////////////
#GET SCHEDULES
#///////////////////////////////////////////////////////////////////////
#Since every policy has different number of schedules and Columns/Propierties in them are named
#same we have to separate them in order to save them gracefully into hash table
#because $schedules will always be an array, even if we have 1 item we will iterate the array,
#this way will lose a if statement after foreach statement whos iteratting the $schedules
$schedules = $pc -match "^Schedule:"
$schindex = @()
foreach($schedule in $schedules){
$schindex += [array]::IndexOf($pc,$schedule)
}
#///////////////////////////////////////////////////////////////////////
#GET LIST OF DICTIONARIES
#///////////////////////////////////////////////////////////////////////
}
}
else {
write-host "This script can only run on Netbackup Windows Servers, $nbpath path incorrect"
}