-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Split-HuduConfigurationsByType.ps1
24 lines (21 loc) · 1.24 KB
/
Split-HuduConfigurationsByType.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
Import-Module ImportExcel
Import-Module HuduAPI
$Path = Read-Host "Provide spreadsheet mapping of ITGlue (configuration type names) to Hudu (asset layout names)"
$APIKey = 'replace-me-with-your-api-key'
$APIBaseUrl = 'https://replace/me/with/your/hudu/URL'
$ALS = Import-Excel $Path
New-HuduAPIKey $APIKey
New-HuduBaseUrl = $APIBaseUrl
$AssetLayouts = Get-HuduAssetLayouts
$Configurations = Get-HuduAssets -AssetLayoutId ($AssetLayouts |? {$_.name -eq 'Configurations'}).id
$ReformedConfigurations = $Configurations |select @{n='type'; e={ ($_.fields |? {$_.label -eq 'Configuration Type Name'}).value}},*
$GroupedReformedConfigurations = $ReformedConfigurations| Group-Object -Property type
# Add ID to each layout
foreach ($AL in $ALS) {$AL|Add-Member -MemberType NoteProperty -Name assetlayout_id -Value ($AssetLayouts|?{$_.name -eq $AL.hudu}).id -Force}
# Move asset layouts
$Results = foreach ($AL in $ALS[0]) {
# Pull Configurations by name
$AssetsToMove = ($GroupedReformedConfigurations |? {$_.name -eq $AL.'IT Glue'}).group
Write-Host "Moving $($AssetsToMove.count) configurations of $($AL.'IT Glue') type to asset layout $($AL.Hudu)" -ForegroundColor Cyan
Move-HuduAssetsToNewLayout -AssetsToMove $AssetsToMove -NewAssetLayoutID $al.assetlayout_id
}