This script was requested by a friend of mine. She had trouble keeping her IP address management under control. A lot of changes on super and subscopes within networks caused her to lose oversight and she was wondering if there wasn’t a clean and automated way of generating documentation for this.
But before we dive into that script, I want to let you all know that the AzGlue function to protect, and help circumvent rate limitations for IT-Glue has been updated. Angus Warren made an amazing update. He added loads of functionality and security measures. If you are using AzGlue right now, I’d suggest to update to the latest version.
Angus his changes have updated the function entirely, and it’s practically a new product all together. I’ll be updating the documentation for this in the coming weeks.
The scripts
So, now let’s get to the scripts, I am sharing two versions again. One for IT-Glue, and one generic HTML version. The IT-Glue version creates the flexible asset for you at first run, and then documents the DHCP settings.
IT-Glue version
You can run this version by hand, using your RMM, or from a scheduled task.
###############$ITGkey="YOURIGLUEKEY"$ITGbaseURI="https://api.eu.itglue.com"$FlexAssetName="DHCP Server - Autodoc"$ITGlueOrgID="ITGLUEORGID"$Description="A logbook for DHCP server witha ll information about scopes, superscopes, etc.."###############Settings IT-Glue logon informationIf(Get-Module-ListAvailable-Name"ITGlueAPI"){Import-moduleITGlueAPI}Else{Install-ModuleITGlueAPI-ForceImport-ModuleITGlueAPI}#Settings IT-Glue logon informationAdd-ITGlueBaseURI-base_uri$ITGbaseURIAdd-ITGlueAPIKey$ITGkeywrite-host"Checking if Flexible Asset exists in IT-Glue."-foregroundColorgreen$FilterID=(Get-ITGlueFlexibleAssetTypes-filter_name$FlexAssetName).dataif(!$FilterID){write-host"Does not exist, creating new."-foregroundColorgreen$NewFlexAssetData=@{type ='flexible-asset-types'attributes=@{name=$FlexAssetNameicon='sitemap'description=$description}relationships=@{"flexible-asset-fields"=@{data=@(@{type ="flexible_asset_fields"attributes=@{order=1name="DHCP Server Name"kind="Text"required=$true"show-in-list"=$true"use-for-title"=$true}},@{type ="flexible_asset_fields"attributes=@{order=2name="DHCP Server Settings"kind="Textbox"required=$false"show-in-list"=$false}},@{type ="flexible_asset_fields"attributes=@{order=3name="DHCP Server Database Information"kind="Textbox"required=$false"show-in-list"=$false}},@{type ="flexible_asset_fields"attributes=@{order=4name="DHCP Domain Authorisation"kind="Textbox"required=$false"show-in-list"=$false}},@{type ="flexible_asset_fields"attributes=@{order=5name="DHCP Scopes"kind="Textbox"required=$false"show-in-list"=$false}},@{type ="flexible_asset_fields"attributes=@{order=6name="DHCP Scope Information"kind="Textbox"required=$false"show-in-list"=$false}},@{type ="flexible_asset_fields"attributes=@{order=7name="DHCP Statistics"kind="Textbox"required=$false"show-in-list"=$false}})}}}New-ITGlueFlexibleAssetTypes-Data$NewFlexAssetData$FilterID=(Get-ITGlueFlexibleAssetTypes-filter_name$FlexAssetName).data}write-host"Starting documentation process."-foregroundColorgreen$DCHPServerSettings=Get-DhcpServerSetting|select-objectActivatePolicies,ConflictDetectionAttempts,DynamicBootp,IsAuthorized,IsDomainJoined,NapEnabled,NpsUnreachableAction,RestoreStatus|ConvertTo-Html-Fragment-PreContent"<h1>DHCP Server Settings</h1>"|Out-String$databaseinfo=Get-DhcpServerDatabase|Select-ObjectBackupInterval,BackupPath,CleanupInterval,FileName,LoggingEnabled,RestoreFromBackup|ConvertTo-Html-Fragment-PreContent"<h1>DHCP Database information</h1>"|Out-String$DHCPDCAuth=Get-DhcpServerInDC|select-objectIPAddress,DnsName|ConvertTo-Html-Fragment-PreContent"<h1>DHCP Domain Controller Authorisations</h1>"|Out-String$Scopes=Get-DhcpServerv4Scope$ScopesAvailable=$Scopes|Select-ObjectScopeId,SubnetMask,StartRange,EndRange,ActivatePolicies,Delay,Description,LeaseDuration,MaxBootpClients,Name,NapEnable,NapProfile,State,SuperscopeName,Type |ConvertTo-Html-Fragment-PreContent"<h1>DHCP Server scopes</h1>"|Out-String$ScopeInfo=foreach($Scopein$scopes){$scope|Get-DhcpServerv4Lease|select-objectScopeId,IPAddress,AddressState,ClientId,ClientType,Description,DnsRegistration,DnsRR,HostName,LeaseExpiryTime|ConvertTo-Html-Fragment-PreContent"<h1>Scope Information: $($Scope.name) - $($scope.ScopeID) </h1>"|Out-String}$DHCPServerStats=Get-DhcpServerv4Statistics|Select-ObjectInUse,Available,Acks,AddressesAvailable,AddressesInUse,Declines,DelayedOffers,Discovers,Naks,Offers,PendingOffers,PercentageAvailable,PercentageInUse,PercentagePendingOffers,Releases,Requests,ScopesWithDelayConfigured,ServerStartTime,TotalAddresses,TotalScope|ConvertTo-Html-Fragment-PreContent"<h1>DHCP Server statistics</h1>"-AsList|Out-Stringwrite-host"Uploading to IT-Glue."-foregroundColorgreen$FlexAssetBody=@{type ='flexible-assets'attributes=@{traits=@{'dhcp-server-name'=$env:computername'dhcp-server-settings'=$DCHPServerSettings'dhcp-server-database-information'=$databaseinfo'dhcp-domain-authorisation'=$DHCPDCAuth'dhcp-scopes'=$ScopesAvailable'dhcp-scope-information'=$ScopeInfo'dhcp-statistics'=$DHCPServerStats}}}write-host"Documenting to IT-Glue"-ForegroundColorGreen$ExistingFlexAsset=(Get-ITGlueFlexibleAssets-filter*flexible_asset_type_id$($filterID.ID)-filter_organization_id$ITGlueOrgID).data|Where-Object{$*.attributes.traits.'dhcp-server-name'-eq$env:computername}#If the Asset does not exist, we edit the body to be in the form of a new asset, if not, we just upload.if(!$ExistingFlexAsset){$FlexAssetBody.attributes.add('organization-id',$ITGlueOrgID)$FlexAssetBody.attributes.add('flexible-asset-type-id',$($filterID.ID))write-host" Creating DHCP Server Log into IT-Glue organisation $ITGlueOrgID"-ForegroundColorGreenNew-ITGlueFlexibleAssets-data$FlexAssetBody}else{write-host" Editing DHCP Server Log into IT-Glue organisation $ITGlueOrgID"-ForegroundColorGreen$ExistingFlexAsset=$ExistingFlexAsset|select-object-last1Set-ITGlueFlexibleAssets-id$ExistingFlexAsset.id-data$FlexAssetBody}
Generic version
As requested for the generic version I’ve included a screenshot of the end results: