Skip to content

Instantly share code, notes, and snippets.

@davejlong
Last active August 6, 2024 14:57
Show Gist options
  • Save davejlong/77e718694361c51f3eb25d08bc6653b0 to your computer and use it in GitHub Desktop.
Save davejlong/77e718694361c51f3eb25d08bc6653b0 to your computer and use it in GitHub Desktop.
Imports all GPOs as Assets into Hudu. Requires an asset with an Embed field named "Policy Report"
# Add logic to install HuduAPI PowerShell Module
Import-Module HuduAPI
New-HuduAPIKey "****"
New-HuduBaseURL "*****"
$CompanyId = 42
$AssetLayoutID = 21
$ReportStore = C:\gpos
# Make sure the report store exists
if (!(Test-Path -Path $ReportStore)) {
New-Item -Path $ReportStore -ItemType Directory
}
# Get current assets to check for existing assets and clean up later
$CurrentAssets = Get-HuduAssets -CompanyId $CompanyId -AssetLayoutId $AssetLayoutID
# Get all GPOs
$gpos = Get-GPO -All
foreach($gpo in $gpos) {
# Get the GPO Report which contains all settings, links, permissions, etc.
$Report = "$ReportStore/$($gpo.DisplayName).html"
Get-GPOReport -Guid $gpo.Id -ReportType Html -Path "$ReportStore/$($gpo.DisplayName).html"
$fields = @(
@{"Policy Report" = (Get-Content -Path $Report)}
)
if ($CurrentAssets -contains $gpo.DisplayName) {
# It's an update
} else {
# It's a new asset
New-HuduAsset -Name $gpo.DisplayName -CompanyId $CompanyId -AssetLayoutId $AssetLayoutID -Fields $fields
}
}
# Add logic to move assets that weren't updated to the museum as they no longer exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment