This repository was archived by the owner on Nov 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAdd_Devices_From_Excel_To_Zone.ps1
More file actions
47 lines (37 loc) · 1.58 KB
/
Add_Devices_From_Excel_To_Zone.ps1
File metadata and controls
47 lines (37 loc) · 1.58 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
<#
.DESCRIPTION
This tool will take an Excel file, look at its "Machine Name" column, and add all of the hosts in it that already exist
in the console to a specific zone.
This is useful in situations where you need to add arbitrary groups not based on some criteria that can be expressed via zone rules.
The Excel file needs to have a column "Machine Name" on the active worksheet, and this has to contain the device names to add to the zone.
.LINK
Blog: http://tietze.io/
Jan Tietze
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[String]$Console,
[Parameter(Mandatory=$false)]
[String]$ZoneName = "Imported from Excel",
[Parameter(Mandatory=$false)]
[String]$ExcelFile = "Add_Devices_From_Excel_To_Zone.xlsx"
)
Import-Module CyCLI
Import-Module ImportExcel
Get-CyAPI -Console $Console
# Creates zone if it does not exist
$Zone = Get-CyZone -Name $ZoneName
if ($Zone -eq $null) {
$Zone = New-CyZone -Name $ZoneName -Criticality Normal
}
# Get list of devices to add to zone
$DevicesToAdd = @( Import-Excel -Path $ExcelFile | Select-Object "Machine Name")
# Identify devices that already exist in tenant
Write-Host -NoNewline "There were $($DevicesToAdd.Count) devices in the Excel file, of which "
$ExistingDevices = @( Get-CyDeviceList | Where-Object { $DevicesToAdd."Machine Name" -Contains $_.name } )
Write-Host "$($ExistingDevices.Count) devices exist in the tenant."
# Add those devices to zone
Write-Host -NoNewline "Adding devices to the zone $($Zone.name)..."
$ExistingDevices | Add-CyDeviceToZone -Zone $Zone
Write-Host "done."