-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrestronWriteInfoFromCSV.ps1
72 lines (55 loc) · 2.06 KB
/
CrestronWriteInfoFromCSV.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
## CSV file must have headers CurrentIP, IPAddress, Hostname, IPMask, Defrouter, MasterIP, IPID
param($filename)
Import-Module PSCrestron
if ([string]::IsNullOrEmpty($filename))
{
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$FileBrowser.filter = 'CSV |*.csv'
[VOID]$FileBrowser.ShowDialog()
$filename = $FileBrowser.FileNames
}
if([string]::IsNullOrEmpty($filename))
{
Write-Host "Invalid File"
}
else
{
Write-Host "Opening CSV" $filename
$csv = Import-Csv $filename
Foreach ($el in $csv)
{
if($el.Secure -like 'yes')
{
Write-Host 'Opening Secure Session to Device at'$el.CurrentIP
$session = Open-CrestronSession -Device $el.CurrentIP -secure -Username "admin" -Password "admin"
$cmd1 = 'hostname ' + $el.Hostname
Write-Host 'Setting:' $cmd1
Invoke-CrestronSession $session $cmd1
$cmd2 = 'IPA 0 ' + $el.IPAddress
Write-Host 'Setting:' $cmd2
Invoke-CrestronSession $session $cmd2
$cmd3 = 'IPMask 0 ' + $el.IPMask
Write-Host 'Setting:' $cmd3
Invoke-CrestronSession $session $cmd3
$cmd4 = 'DefRouter 0 ' + $el.Defrouter
Write-Host 'Setting:' $cmd4
Invoke-CrestronSession $session $cmd4
$cmd5 = 'Addm ' + $el.IPID + ' ' + $el.MasterIP
Write-Host 'Setting:' $cmd5
Invoke-CrestronSession $session $cmd5
$cmd6 = "DHCP 0 off"
Write-Host 'Setting:' $cmd6
Invoke-CrestronSession $session $cmd6
$cmd7 = "REBOOT"
Write-Host 'Rebooting Device'
Invoke-CrestronSession $session $cmd7
Write-Host 'Closing Session'
Close-CrestronSession $session
}
else
{
Write-Host 'Opening Plain Session to Device at '$el.IPAddress
}
}
}