forked from palmersndrsn/crestronEDK-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipUpdater.ps1
184 lines (170 loc) · 8.04 KB
/
ipUpdater.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<#
2. Update the devices-ip.csv file as required, order is important.
3. The device with the LAN connection must be last.
#>
# minimum required version
#Requires -Version 3
Set-StrictMode -Version Latest
# import the module
Import-Module PSCrestron
# build configs
Write-Host "building avaliable configs..."
# py "C:\Users\p_sanderson\Documents\Python_Scripts\config_file_editor.py"\
# get the device list
Write-Host 'Getting the device list...'
$devs = Import-Csv (Join-Path $PSScriptRoot 'devices-ip.csv')
# iterate the devices in order
foreach ($d in $devs)
{
function Get-reboot_device
{
start-sleep 2
if($d.username-and$d.password)
{
Write-Host "rebooting $($d.Room_Number)..."
Invoke-CrestronCommand -Device $d.Device -Command "reboot" -username $d.username -secure -password $d.password -Timeout 20
}
elseif ($d.Description.StartsWith("DM-")) {
# reboot to complete
Write-Host "rebooting $($d.Room_Number)..."
Invoke-CrestronCommand -Device $d.Device -Command "reboot" -Timeout 20
}
else {
# reboot to complete
Write-Host "rebooting $($d.Room_Number)..."
Invoke-CrestronCommand -Device $d.Device -Command "reboot" -secure -Timeout 20
}
}
# checks for device
if($d.Device)
{
write-host "Beginning: $($d.device),$($d.Description),$($d.Room_Number)..."
# checks if the device is a processor
if($d.Description.StartsWith("RMC3")-Or$d.Description.StartsWith("DMPS")-or$d.Description.StartsWith("CP3"))
{
# checks if there is a config file to push
if($d.config_file_name)
{
if($d.program_name)
{
# makes folder if required
Invoke-CrestronCommand -Device $d.Device -Command "MAKEDIR nvram\\$($d.program_name)" -secure -Timeout 20
# send config to that folder
Send-FTPFile -Device $d.Device -LocalFile (Join-Path $PSScriptRoot "\\$($d.config_file_name)-$($d.Room_Number).json") -secure -RemoteFile "\\NVRAM\\$($d.program_name)\\$($d.config_file_name)-$($d.Room_Number).json" # -Timeout 60
Write-Host "Sending Config $($d.config_file_name)-$($d.Room_Number).json to $($d.program_name)"
} else {
# send config to root folder
write-host
Send-FTPFile -Device $d.Device -LocalFile (Join-Path $PSScriptRoot "\\$($d.config_file_name)-$($d.Room_Number).json") -secure -RemoteFile "\\NVRAM\\$($d.config_file_name)-$($d.Room_Number).json" # -Timeout 60
Write-Host (Join-Path $PSScriptRoot "\\$($d.config_file_name)-$($d.Room_Number).json to NVRAM")
}
start-sleep 5
}
# add 0 for processors
$zero = " 0"
# checks if nvx
} elseif ($d.Description.StartsWith("DM-NVX")) {
# $secure = "-Password admin -Secure -Username admin"
if($d.IPID-and$d.processorIP-and$d.username-and$d.password)
{
# sets ipid for nvx
Invoke-CrestronCommand -Device $d.Device -Command "addmaster $($d.IPID) $($d.processorIP)" -username $d.username -secure -password $d.password -Timeout 20
Write-Host "setting ipid master:$($d.processorIP) IPID $($d.IPID)"
if(-Not$d.IP)
{
Get-reboot_device
}
} else {
write-host "could not find ip/ssh credentials"
}
$zero = ""
} elseif ($d.Description.StartsWith("DM-")) {
# no 0 for dm endpoints
$zero = ""
# checks for ipid requirements and not a processor
if($d.IPID-and$d.processorIP)
{
# sets ipid for dm devices
Invoke-CrestronCommand -Device $d.Device -Command "addmaster $($d.IPID) $($d.processorIP)" -Timeout 20
Write-Host "setting ipid master:$($d.processorIP) IPID $($d.IPID)"
if(-Not$d.IP)
{
Get-reboot_device
}
}
} else {
write-host "description not found"
}
# sets all network settings for secure devices
if ($d.IP-and$d.Subnet-and$d.Gateway-and$d.username-and$d.password)
{
# turn off dhcp
write-Host "Updating IP $($d.Device) to $($d.Room_Number)..."
Invoke-CrestronCommand -Device $d.Device -Command "dhcp off" -username $d.username -secure -password $d.password -Timeout 20
write-host "dhcp off"
# set ip
Invoke-CrestronCommand -Device $d.Device -Command "ipa $($d.IP)" -username $d.username -secure -password $d.password -Timeout 20
write-host "ipa $($d.IP)"
# set subnet
Invoke-CrestronCommand -Device $d.Device -Command "ipmask $($d.Subnet)" -username $d.username -secure -password $d.password -Timeout 20
write-host "ipmask $($d.Subnet)"
# set gateway
Invoke-CrestronCommand -Device $d.Device -Command "defr $($d.Gateway)" -username $d.username -secure -password $d.password -Timeout 20
write-host "defr $($d.Gateway)"
# check for host
if($d.Hostname)
{
Invoke-CrestronCommand -Device $d.Device -Command "hostname $($d.Hostname)" -username $d.username -secure -password $d.password -Timeout 20
Write-Host "Hostname Set $($d.Hostname)"
}
Get-reboot_device
}
# not secure network config
elseif($d.IP-and$d.Subnet-and$d.Gateway)
{
if ($d.Description.StartsWith("DM-")) {
Write-Host "Updating IP $($d.Device) to $($d.Room_Number)..."
Invoke-CrestronCommand -Device $d.Device -Command "dhcp$zero off" -Timeout 20
write-host "dhcp $zero off"
# set ip
Invoke-CrestronCommand -Device $d.Device -Command "ipa$zero $($d.IP)" -Timeout 20
write-host "ipa $zero $($d.IP)"
# set subnet
Invoke-CrestronCommand -Device $d.Device -Command "ipmask$zero $($d.Subnet)" -Timeout 20
write-host "ipmask $zero $($d.Subnet)"
# set gateway
Invoke-CrestronCommand -Device $d.Device -Command "defr$zero $($d.Gateway)" -Timeout 20
write-host "defr $zero $($d.Gateway)"
# check for host
if($d.Hostname)
{
Invoke-CrestronCommand -Device $d.Device -Command "hostname $($d.Hostname)" -Timeout 20
Write-Host "Hostname Set $($d.Hostname)"
}
}
else {
Write-Host "Updating IP $($d.Device) to $($d.Room_Number)..."
Invoke-CrestronCommand -Device $d.Device -Command "dhcp$zero off" -secure -Timeout 20
write-host "dhcp $zero off"
# set ip
Invoke-CrestronCommand -Device $d.Device -Command "ipa$zero $($d.IP)" -secure -Timeout 20
write-host "ipa $zero $($d.IP)"
# set subnet
Invoke-CrestronCommand -Device $d.Device -Command "ipmask$zero $($d.Subnet)" -secure -Timeout 20
write-host "ipmask $zero $($d.Subnet)"
# set gateway
Invoke-CrestronCommand -Device $d.Device -Command "defr$zero $($d.Gateway)" -secure -Timeout 20
write-host "defr $zero $($d.Gateway)"
# check for host
if($d.Hostname)
{
Invoke-CrestronCommand -Device $d.Device -Command "hostname $($d.Hostname)" -secure -Timeout 20
Write-Host "Hostname Set $($d.Hostname)"
}
}
Get-reboot_device
}
}
}
Write-Host 'Done.'
Read-Host -Prompt “Press Enter to exit”