HuduAPI.psm1
#Region './Private/Get-HuduCompanyFolders.ps1' 0 function Get-HuduCompanyFolders { [CmdletBinding()] Param ( [PSCustomObject]$FoldersRaw ) $RootFolders = $FoldersRaw | Where-Object { $null -eq $_.parent_folder_id } $ReturnObject = [PSCustomObject]@{} foreach ($folder in $RootFolders) { $SubFolders = Get-HuduSubFolders -id $folder.id -FoldersRaw $FoldersRaw foreach ($SubFolder in $SubFolders) { $Folder | add-member -Membertype NoteProperty -Name $(Get-HuduFolderCleanName $($SubFolder.PSObject.Properties.name)) -Value $SubFolder.PSObject.Properties.value } $ReturnObject | add-member -Membertype NoteProperty -Name $(Get-HuduFolderCleanName $($folder.name)) -Value $folder } return $ReturnObject } #EndRegion './Private/Get-HuduCompanyFolders.ps1' 18 #Region './Private/Get-HuduFolderCleanName.ps1' 0 function Get-HuduFolderCleanName { [CmdletBinding()] param( [string]$Name ) $FieldNames = @("id", "company_id", "icon", "description", "name", "parent_folder_id", "created_at", "updated_at") if ($Name -in $FieldNames) { Return "fld_$Name" } else { Return $Name } } #EndRegion './Private/Get-HuduFolderCleanName.ps1' 16 #Region './Private/Get-HuduSubFolders.ps1' 0 function Get-HuduSubFolders { [CmdletBinding()] Param( [int]$id, [PSCustomObject]$FoldersRaw ) $SubFolders = $FoldersRaw | where-Object { $_.parent_folder_id -eq $id } $ReturnFolders = [System.Collections.ArrayList]@() foreach ($Folder in $SubFolders) { $SubSubFolders = Get-HuduSubFolders -id $Folder.id -FoldersRaw $FoldersRaw foreach ($AddFolder in $SubSubFolders) { $null = $folder | add-member -Membertype NoteProperty -Name $(Get-HuduFolderCleanName $($AddFolder.PSObject.Properties.name)) -Value $AddFolder.PSObject.Properties.value } $ReturnObject = [PSCustomObject]@{ $(Get-HuduFolderCleanName $($Folder.name)) = $Folder } $null = $ReturnFolders.add($ReturnObject) } return $ReturnFolders } #EndRegion './Private/Get-HuduSubFolders.ps1' 24 #Region './Private/Invoke-HuduRequest.ps1' 0 function Invoke-HuduRequest { <# .SYNOPSIS Main Hudu API function .DESCRIPTION Calls Hudu API with token .PARAMETER Method GET,POST,DELETE,PUT,etc .PARAMETER Path Path to API endpoint .PARAMETER Params Hashtable of parameters .PARAMETER Body JSON encoded body string .PARAMETER Form Multipart form data .EXAMPLE Invoke-HuduRequest -Resource '/api/v1/articles' -Method GET #> [CmdletBinding()] Param( [Parameter()] [string]$Method = 'GET', [Parameter()] [ValidateNotNullOrEmpty()] [string]$Resource, [Parameter()] [hashtable]$Params = @{}, [Parameter()] [string]$Body, [Parameter()] [hashtable]$Form ) $HuduAPIKey = Get-HuduApiKey $HuduBaseURL = Get-HuduBaseURL # Assemble parameters $ParamCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) # Sort parameters foreach ($Item in ($Params.GetEnumerator() | Sort-Object -CaseSensitive -Property Key)) { $ParamCollection.Add($Item.Key, $Item.Value) } # Query string $Request = $ParamCollection.ToString() $Headers = @{ 'x-api-key' = (New-Object PSCredential 'user', $HuduAPIKey).GetNetworkCredential().Password; } $ContentType = 'application/json; charset=utf-8' $Uri = '{0}{1}' -f $HuduBaseURL, $Resource # Make API call URI if ($Request) { $UriBuilder = [System.UriBuilder]$Uri $UriBuilder.Query = $Request $Uri = $UriBuilder.Uri } Write-Verbose ( '{0} [{1}]' -f $Method, $Uri ) $RestMethod = @{ Method = $Method Uri = $Uri Headers = $Headers ContentType = $ContentType } if ($Body) { $RestMethod.Body = $Body Write-Verbose $Body } if ($Form) { $RestMethod.Form = $Form Write-Verbose ( $Form | ConvertTo-Json ) } try { $Results = Invoke-RestMethod @RestMethod } catch { if ("$_".trim() -eq 'Retry later' -or "$_".trim() -eq 'The remote server returned an error: (429) Too Many Requests.') { Write-Information 'Hudu API Rate limited. Waiting 30 Seconds then trying again' Start-Sleep 30 $Results = Invoke-HuduRequest @RestMethod } else { Write-Error "'$_'" } } $Results } #EndRegion './Private/Invoke-HuduRequest.ps1' 110 #Region './Private/Invoke-HuduRequestPaginated.ps1' 0 function Invoke-HuduRequestPaginated { <# .SYNOPSIS Paginated requests to Hudu API .DESCRIPTION Wraps Invoke-HuduRequest with page sizes .PARAMETER HuduRequest Request to paginate .PARAMETER Property Property name to return (don't specify to return entire response object) .PARAMETER PageSize Number of results to return per page (default 1000) #> [CmdletBinding()] Param( [hashtable]$HuduRequest, [string]$Property, [int]$PageSize = 1000 ) $i = 1 do { $HuduRequest.Params.page = $i $HuduRequest.Params.page_size = $PageSize $Response = Invoke-HuduRequest @HuduRequest $i++ if ($Property) { $Response.$Property } else { $Response } } while (($Property -and $Response.$Property.count % $PageSize -eq 0 -and $Response.$Property.count -ne 0) -or (!$Property -and $Response.count % $PageSize -eq 0 -and $Response.count -ne 0)) } #EndRegion './Private/Invoke-HuduRequestPaginated.ps1' 41 #Region './Private/ArgumentCompleters/AssetLayoutCompleter.ps1' 0 $AssetLayoutCompleter = { param ( $CommandName, $ParamName, $AssetLayout, $CommandAst, $fakeBoundParameters ) if (!$script:AssetLayouts) { Get-HuduAssetLayouts | Out-Null } $AssetLayout = $AssetLayout -replace "'", '' ($script:AssetLayouts).name | Where-Object { $_ -match "$AssetLayout" } | ForEach-Object { "'$_'" } } Register-ArgumentCompleter -CommandName Get-HuduAssets -ParameterName AssetLayout -ScriptBlock $AssetLayoutCompleter #EndRegion './Private/ArgumentCompleters/AssetLayoutCompleter.ps1' 18 #Region './Public/Get-HuduActivityLogs.ps1' 0 function Get-HuduActivityLogs { <# .SYNOPSIS Get activity logs for account .DESCRIPTION Calls Hudu API to retrieve activity logs with filters .PARAMETER UserId Filter logs by user_id .PARAMETER UserEmail Filter logs by email address .PARAMETER ResourceId Filter logs by resource id. Must be coupled with resource_type .PARAMETER ResourceType Filter logs by resource type (Asset, AssetPassword, Company, Article, etc.). Must be coupled with resource_id .PARAMETER ActionMessage Filter logs by action .PARAMETER StartDate Filter logs by start date. Converts string to ISO 8601 format .PARAMETER EndDate Filter logs by end date, should be coupled with start date to limit results .EXAMPLE Get-HuduActivityLogs -StartDate 2023-02-01 #> [CmdletBinding()] Param ( [Alias('user_id')] [Int]$UserId = '', [Alias('user_email')] [String]$UserEmail = '', [Alias('resource_id')] [Int]$ResourceId = '', [Alias('resource_type')] [String]$ResourceType = '', [Alias('action_message')] [String]$ActionMessage = '', [Alias('start_date')] [DateTime]$StartDate, [Alias('end_date')] [DateTime]$EndDate ) $Params = @{} if ($UserId) { $Params.user_id = $UserId } if ($UserEmail) { $Params.user_email = $UserEmail } if ($ResourceId) { $Params.resource_id = $ResourceId } if ($ResourceType) { $Params.resource_type = $ResourceType } if ($ActionMessage) { $Params.action_message = $ActionMessage } if ($StartDate) { $ISO8601Date = $StartDate.ToString('o'); $Params.start_date = $ISO8601Date } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/activity_logs' Params = $Params } $AllActivity = Invoke-HuduRequestPaginated -HuduRequest $HuduRequest if ($EndDate) { $AllActivity = $AllActivity | Where-Object { $([DateTime]::Parse($_.created_at)) -le $EndDate } } return $AllActivity } #EndRegion './Public/Get-HuduActivityLogs.ps1' 78 #Region './Public/Get-HuduApiKey.ps1' 0 function Get-HuduApiKey { <# .SYNOPSIS Get Hudu API key .DESCRIPTION Returns Hudu API key in securestring format .EXAMPLE Get-HuduApiKey #> [CmdletBinding()] Param() if ($null -eq $Int_HuduAPIKey) { Write-Error 'No API key has been set. Please use New-HuduAPIKey to set it.' } else { $Int_HuduAPIKey } } #EndRegion './Public/Get-HuduApiKey.ps1' 23 #Region './Public/Get-HuduAppInfo.ps1' 0 function Get-HuduAppInfo { <# .SYNOPSIS Retrieve information regarding API .DESCRIPTION Calls Hudu API to retrieve version number and date .EXAMPLE Get-HuduAppInfo #> [CmdletBinding()] Param() try { Invoke-HuduRequest -Resource '/api/v1/api_info' } catch { [PSCustomObject]@{ version = '0.0.0.0' date = '2000-01-01' } } } #EndRegion './Public/Get-HuduAppInfo.ps1' 27 #Region './Public/Get-HuduArticles.ps1' 0 function Get-HuduArticles { <# .SYNOPSIS Get Knowledge Base Articles .DESCRIPTION Calls Hudu API to retrieve KB articles by Id or a list .PARAMETER Id Id of the Article .PARAMETER CompanyId Filter by company id .PARAMETER Name Filter by name of article .PARAMETER Slug Filter by slug of article .EXAMPLE Get-HuduArticles -Name 'Article name' #> [CmdletBinding()] Param ( [Int]$Id = '', [Alias('company_id')] [Int]$CompanyId = '', [String]$Name = '', [String]$Slug ) if ($Id) { Invoke-HuduRequest -Method get -Resource "/api/v1/articles/$Id" } else { $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($Name) { $Params.name = $Name } if ($Slug) { $Params.slug = $Slug } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/articles' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest } } #EndRegion './Public/Get-HuduArticles.ps1' 54 #Region './Public/Get-HuduAssetLayoutFieldID.ps1' 0 function Get-HuduAssetLayoutFieldID { <# .SYNOPSIS Get Hudu Asset Layout Field ID .DESCRIPTION Retrieves ID for Hudu Asset Layout Fields .PARAMETER Name Name of Field .PARAMETER LayoutId Asset Layout Id .EXAMPLE Get-HuduAssetLayoutFieldID -Name 'Extra Info' -LayoutId 1 #> [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Alias('asset_layout_id')] [Parameter(Mandatory = $true)] [Int]$LayoutId ) $Layout = Get-HuduAssetLayouts -LayoutId $LayoutId $Fields = [Collections.Generic.List[Object]]($Layout.fields) $Index = $Fields.FindIndex( { $args[0].label -eq $Name } ) $Fields[$Index].id } #EndRegion './Public/Get-HuduAssetLayoutFieldID.ps1' 34 #Region './Public/Get-HuduAssetLayouts.ps1' 0 function Get-HuduAssetLayouts { <# .SYNOPSIS Get a list of Asset Layouts .DESCRIPTION Call Hudu API to retrieve asset layouts for server .PARAMETER Name Filter by name of Asset Layout .PARAMETER LayoutId Id of Asset Layout .PARAMETER Slug Filter by url slug .EXAMPLE Get-HuduAssetLayouts -Name 'Contacts' #> [CmdletBinding()] Param ( [String]$Name, [Alias('id', 'layout_id')] [int]$LayoutId, [String]$Slug ) $HuduRequest = @{ Resource = '/api/v1/asset_layouts' Method = 'GET' } if ($LayoutId) { $HuduRequest.Resource = '{0}/{1}' -f $HuduRequest.Resource, $LayoutId $AssetLayout = Invoke-HuduRequest @HuduRequest return $AssetLayout.asset_layout } else { $Params = @{} if ($Name) { $Params.name = $Name } if ($Slug) { $Params.slug = $Slug } $HuduRequest.Params = $Params $AssetLayouts = Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'asset_layouts' -PageSize 25 if (!$Name -and !$Slug) { $script:AssetLayouts = $AssetLayouts | Sort-Object -Property name } $AssetLayouts } } #EndRegion './Public/Get-HuduAssetLayouts.ps1' 55 #Region './Public/Get-HuduAssets.ps1' 0 function Get-HuduAssets { <# .SYNOPSIS Get a list of Assets .DESCRIPTION Call Hudu API to retrieve Assets .PARAMETER Id Id of requested asset .PARAMETER AssetLayoutId Id of the requested asset layout .PARAMETER AssetLayout Name of the requested asset layout .PARAMETER CompanyId Id of the requested company .PARAMETER Name Filter by name .PARAMETER Archived Show archived results .PARAMETER PrimarySerial Filter by primary serial .PARAMETER Slug Filter by slug .EXAMPLE Get-HuduAssets -AssetLayout 'Contacts' #> [CmdletBinding()] Param ( [Int]$Id = '', [Alias('asset_layout_id')] [Int]$AssetLayoutId = '', [string]$AssetLayout, [Alias('company_id')] [Int]$CompanyId = '', [String]$Name = '', [switch]$Archived, [Alias('primary_serial')] [String]$PrimarySerial = '', [String]$Slug ) if ($AssetLayout) { if (!$script:AssetLayouts) { Get-HuduAssetLayouts | Out-Null } $AssetLayoutId = $script:AssetLayouts | Where-Object { $_.name -eq $AssetLayout } | Select-Object -ExpandProperty id } if ($id -and $CompanyId) { $HuduRequest = @{ Resource = "/api/v1/companies/$CompanyId/assets/$Id" Method = 'GET' } Invoke-HuduRequest @HuduRequest } else { $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($AssetLayoutId) { $Params.asset_layout_id = $AssetLayoutId } if ($Name) { $Params.name = $Name } if ($Archived.IsPresent) { $params.archived = $Archived.IsPresent } if ($PrimarySerial) { $Params.primary_serial = $PrimarySerial } if ($Id) { $Params.id = $Id } if ($Slug) { $Params.slug = $Slug } $HuduRequest = @{ Resource = '/api/v1/assets' Method = 'GET' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property assets } } #EndRegion './Public/Get-HuduAssets.ps1' 83 #Region './Public/Get-HuduBaseURL.ps1' 0 function Get-HuduBaseURL { <# .SYNOPSIS Get Hudu Base URL .DESCRIPTION Returns Hudu Base URL .EXAMPLE Get-HuduBaseURL #> [CmdletBinding()] Param() if ($null -eq $Int_HuduBaseURL) { Write-Error 'No Base URL has been set. Please use New-HuduBaseURL to set it.' } else { $Int_HuduBaseURL } } #EndRegion './Public/Get-HuduBaseURL.ps1' 23 #Region './Public/Get-HuduCard.ps1' 0 function Get-HuduCard { <# .SYNOPSIS Get Integration Cards .DESCRIPTION Lookup cards with outside integration details .PARAMETER IntegrationSlug Identifier of outside integration .PARAMETER IntegrationId ID in the integration. Must be present, unless integration_identifier is set .PARAMETER IntegrationIdentifier Identifier in the integration (if integration_id is not set) .EXAMPLE Get-HuduCard -IntegrationSlug cw_manage -IntegrationId 1 #> [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Alias('integration_slug')] [String]$IntegrationSlug, [Alias('integration_id')] [String]$IntegrationId, [Alias('integration_identifier')] [String]$IntegrationIdentifier ) $Params = @{ integration_slug = $IntegrationSlug } if ($IntegrationId) { $Params.integration_id = $IntegrationId } if ($IntegrationIdentifier) { $Params.integration_identifier = $IntegrationIdentifier } if (!$IntegrationId -and !$IntegrationIdentifier) { throw 'IntegrationId or IntegrationIdentifier required' } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/cards/lookup' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property integrator_cards } #EndRegion './Public/Get-HuduCard.ps1' 54 #Region './Public/Get-HuduCompanies.ps1' 0 function Get-HuduCompanies { <# .SYNOPSIS Get a list of companies .DESCRIPTION Call Hudu API to retrieve company list .PARAMETER Id Filter companies by id .PARAMETER Name Filter companies by name .PARAMETER PhoneNumber filter companies by phone number .PARAMETER Website Filter companies by website .PARAMETER City Filter companies by city .PARAMETER State Filter companies by state .PARAMETER Search Filter by search query .PARAMETER Slug Filter by url slug .PARAMETER IdInIntegration Filter companies by id/identifier in PSA/RMM/outside integration .EXAMPLE Get-HuduCompanies -Search 'Vendor' #> [CmdletBinding()] Param ( [String]$Name = '', [Alias('phone_number')] [String]$PhoneNumber = '', [String]$Website = '', [String]$City = '', [String]$State = '', [Alias('id_in_integration')] [Int]$IdInIntegration = '', [Int]$Id = '', [string]$Search, [String]$Slug ) if ($Id) { $Company = Invoke-HuduRequest -Method get -Resource "/api/v1/companies/$Id" return $Company } else { $Params = @{} if ($Name) { $Params.name = $Name } if ($PhoneNumber) { $Params.phone_number = $PhoneNumber } if ($Website) { $Params.website = $Website } if ($City) { $Params.city = $City } if ($State) { $Params.state = $State } if ($IdInIntegration) { $Params.id_in_integration = $IdInIntegration } if ($Search) { $Params.search = $Search } if ($Slug) { $Params.slug = $Slug } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/companies' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'companies' } } #EndRegion './Public/Get-HuduCompanies.ps1' 80 #Region './Public/Get-HuduExpirations.ps1' 0 function Get-HuduExpirations { <# .SYNOPSIS Get expirations for account .DESCRIPTION Calls Hudu API to retrieve expirations .PARAMETER CompanyId Filter expirations by company_id .PARAMETER ExpirationType Filter expirations by expiration type (undeclared, domain, ssl_certificate, warranty, asset_field, article_expiration) .PARAMETER ResourceId Filter logs by resource id. Must be coupled with resource_type .PARAMETER ResourceType Filter logs by resource type (Asset, AssetPassword, Company, Article, etc.). Must be coupled with resource_id .EXAMPLE Get-HuduExpirations -ExpirationType domain #> [CmdletBinding()] Param ( [Alias('company_id')] [Int]$CompanyId = '', [ValidateSet('undeclared', 'domain', 'ssl_certificate', 'warranty', 'asset_field', 'article_expiration')] [Alias('expiration_type')] [String]$ExpirationType = '', [Alias('resource_id')] [Int]$ResourceId = '', [Alias('resource_type')] [String]$ResourceType = '' ) $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($ExpirationType) { $Params.expiration_type = $ExpirationType } if ($ResourceType) { $Params.resource_type = $ResourceType } if ($ResourceId) { $Params.resource_id = $ResourceId } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/expirations' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest } #EndRegion './Public/Get-HuduExpirations.ps1' 56 #Region './Public/Get-HuduFolderMap.ps1' 0 function Get-HuduFolderMap { [CmdletBinding()] Param ( [Alias('company_id')] [Int]$CompanyId = '' ) if ($CompanyId) { $FoldersRaw = Get-HuduFolders -company_id $CompanyId $SubFolders = Get-HuduCompanyFolders -FoldersRaw $FoldersRaw } else { $FoldersRaw = Get-HuduFolders $FoldersProcessed = $FoldersRaw | Where-Object { $null -eq $_.company_id } $SubFolders = Get-HuduCompanyFolders -FoldersRaw $FoldersProcessed } return $SubFolders } #EndRegion './Public/Get-HuduFolderMap.ps1' 22 #Region './Public/Get-HuduFolders.ps1' 0 function Get-HuduFolders { <# .SYNOPSIS Get a list of Folders .DESCRIPTION Calls Hudu API to retrieve folders .PARAMETER Id Id of the folder .PARAMETER Name Filter by name .PARAMETER CompanyId Filter by company_id .EXAMPLE Get-HuduFolders #> [CmdletBinding()] Param ( [Int]$Id = '', [String]$Name = '', [Alias('company_id')] [Int]$CompanyId = '' ) if ($id) { $Folder = Invoke-HuduRequest -Method get -Resource "/api/v1/folders/$id" return $Folder.Folder } else { $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($Name) { $Params.name = $Name } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/folders' Params = $Params } Invoke-HuduPaginatedRequest -HuduRequest $HuduRequest -Property folders } } #EndRegion './Public/Get-HuduFolders.ps1' 49 #Region './Public/Get-HuduIntegrationMatchers.ps1' 0 function Get-HuduIntegrationMatchers { <# .SYNOPSIS List matchers for an integration .DESCRIPTION Calls Hudu API to get list of integration matching .PARAMETER IntegrationId ID of the integration. Can be found in the URL when editing an integration .PARAMETER Matched Filter on whether the company already been matched .PARAMETER SyncId Filter by ID of the record in the integration. This is used if the id that the integration uses is an integer. .PARAMETER Identifier Filter by Identifier in the integration (if sync_id is not set). This is used if the id that the integration uses is a string. .PARAMETER CompanyId Filter on company id .EXAMPLE Get-HuduIntegrationMatchers -IntegrationId 1 #> [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [int]$IntegrationId, [switch]$Matched, [int]$SyncId = '', [string]$Identifier = '', [int]$CompanyId ) $Params = @{ integration_id = $IntegrationId } if ($Matched.IsPresent) { $Params.matched = 'true' } if ($CompanyId) { $Params.company_id = $CompanyId } if ($Identifier) { $Params.identifier = $Identifier } if ($SyncId) { $Params.sync_id = $SyncId } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/matchers' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'matchers' } #EndRegion './Public/Get-HuduIntegrationMatchers.ps1' 59 #Region './Public/Get-HuduMagicDashes.ps1' 0 function Get-HuduMagicDashes { <# .SYNOPSIS Get all Magic Dash Items .DESCRIPTION Call Hudu API to retrieve Magic Dashes .PARAMETER CompanyId Filter by company id .PARAMETER Title Filter by title .EXAMPLE Get-HuduMagicDashes -Title 'Microsoft 365 - ...' #> Param ( [Alias('company_id')] [Int]$CompanyId, [String]$Title ) $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($Title) { $Params.title = $Title } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/magic_dash' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest } #EndRegion './Public/Get-HuduMagicDashes.ps1' 37 #Region './Public/Get-HuduObjectByUrl.ps1' 0 function Get-HuduObjectByUrl { <# .SYNOPSIS Get Hudu object from URL .DESCRIPTION Calls Hudu API to retrieve object based on URL string .PARAMETER Url Url to retrieve object from .EXAMPLE Get-HuduObject -Url https://your-hudu-server/a/some-asset-1z8z7a #> [CmdletBinding()] Param ( [uri]$Url ) if ((Get-HuduBaseURL) -match $Url.Authority) { $null, $Type, $Slug = $Url.PathAndQuery -split '/' $SlugSplat = @{ Slug = $Slug } switch ($Type) { 'a' { # Asset Get-HuduAssets @SlugSplat } 'admin' { # Admin path $null, $null, $Type, $Slug = $Url.PathAndQuery -split '/' $SlugSplat = @{ Slug = $Slug } switch ($Type) { 'asset_layouts' { # Asset layouts Get-HuduAssetLayouts @SlugSplat } } } 'c' { # Company Get-HuduCompanies @SlugSplat } 'kba' { # KB article Get-HuduArticles @SlugSplat } 'passwords' { # Passwords Get-HuduPasswords @SlugSplat } 'websites' { # Website Get-HuduWebsites @SlugSplat } default { Write-Error "Unsupported object type $Type" } } } else { Write-Error 'Provided URL does not match Hudu Base URL' } } #EndRegion './Public/Get-HuduObjectByUrl.ps1' 72 #Region './Public/Get-HuduPasswords.ps1' 0 function Get-HuduPasswords { <# .SYNOPSIS Get a list of Passwords .DESCRIPTION Calls Hudu API to list password assets .PARAMETER Id Id of the password .PARAMETER CompanyId Filter by company id .PARAMETER Name Filter by password name .PARAMETER Slug Filter by url slug .PARAMETER Search Filter by search query .EXAMPLE Get-HuduPasswords -CompanyId 1 #> [CmdletBinding()] Param ( [Int]$Id, [Alias('company_id')] [Int]$CompanyId, [String]$Name, [String]$Slug, [string]$Search ) if ($Id) { $Password = Invoke-HuduRequest -Method get -Resource "/api/v1/asset_passwords/$id" return $Password } else { $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($Name) { $Params.name = $Name } if ($Slug) { $Params.slug = $Slug } if ($Search) { $Params.search = $Search } } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/asset_passwords' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'asset_passwords' } #EndRegion './Public/Get-HuduPasswords.ps1' 62 #Region './Public/Get-HuduProcesses.ps1' 0 function Get-HuduProcesses { <# .SYNOPSIS Get a list of Procedures (Processes) .DESCRIPTION Calls Hudu API to retrieve list of procedures .PARAMETER Id Id of the Procedure .PARAMETER CompanyId Filter by company id .PARAMETER Name Fitler by name of article .PARAMETER Slug Filter by url slug .EXAMPLE Get-HuduProcedures -Name 'Procedure 1' #> [CmdletBinding()] Param ( [Int]$Id = '', [Alias('company_id')] [Int]$CompanyId = '', [String]$Name = '', [String]$Slug ) if ($Id) { Invoke-HuduRequest -Method get -Resource "/api/v1/procedures/$id" } else { $Params = @{} if ($CompanyId) { $Params.company_id = $CompanyId } if ($Name) { $Params.name = $Name } if ($Slug) { $Params.slug = $Slug } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/procedures' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'procedures' } } #EndRegion './Public/Get-HuduProcesses.ps1' 54 #Region './Public/Get-HuduPublicPhotos.ps1' 0 function Get-HuduPublicPhotos { <# .SYNOPSIS Get a list of Public_Photos .DESCRIPTION Calls Hudu API to retrieve public photos .EXAMPLE Get-HuduPublicPhotos #> [CmdletBinding()] Param() $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/public_photos' Params = @{} } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'public_photos' } #EndRegion './Public/Get-HuduPublicPhotos.ps1' 23 #Region './Public/Get-HuduRelations.ps1' 0 function Get-HuduRelations { <# .SYNOPSIS Get a list of all relations .DESCRIPTION Calls Hudu API to retrieve object relationsihps .EXAMPLE Get-HuduRelations -CompanyId 1 #> [CmdletBinding()] Param() $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/relations' Params = @{} } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest -Property 'relations' } #EndRegion './Public/Get-HuduRelations.ps1' 24 #Region './Public/Get-HuduWebsites.ps1' 0 function Get-HuduWebsites { <# .SYNOPSIS Get a list of all websites .DESCRIPTION Calls Hudu API to get websites .PARAMETER Name Filter websites by name .PARAMETER Id ID of website .PARAMETER Slug Filter by url slug .PARAMETER Search Fitler by search query .EXAMPLE Get-HuduWebsites -Search 'domain.com' #> [CmdletBinding()] Param ( [String]$Name, [Alias('website_id')] [Int]$WebsiteId, [String]$Slug, [string]$Search ) if ($WebsiteId) { Invoke-HuduRequest -Method get -Resource "/api/v1/websites/$($WebsiteId)" } else { $Params = @{} if ($Name) { $Params.name = $Name } if ($Slug) { $Params.slug = $Slug } if ($Search) { $Params.search = $Search } $HuduRequest = @{ Method = 'GET' Resource = '/api/v1/websites' Params = $Params } Invoke-HuduRequestPaginated -HuduRequest $HuduRequest } } #EndRegion './Public/Get-HuduWebsites.ps1' 52 #Region './Public/Initialize-HuduFolder.ps1' 0 function Initialize-HuduFolder { [CmdletBinding()] param( [String[]]$FolderPath, [Alias("company_id")] [int]$CompanyId ) if ($CompanyId) { $FolderMap = Get-HuduFolderMap -company_id $CompanyId } else { $FolderMap = Get-HuduFolderMap } $CurrentFolder = $Foldermap foreach ($Folder in $FolderPath) { if ($CurrentFolder.$(Get-HuduFolderCleanName $Folder)) { $CurrentFolder = $CurrentFolder.$(Get-HuduFolderCleanName $Folder) } else { $CurrentFolder = (New-HuduFolder -name $Folder -company_id $CompanyID -parent_folder_id $CurrentFolder.id).folder } } Return $CurrentFolder } #EndRegion './Public/Initialize-HuduFolder.ps1' 26 #Region './Public/New-HuduAPIKey.ps1' 0 function New-HuduAPIKey { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Scope = 'Function')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function')] [CmdletBinding()] Param ( [Parameter(Mandatory = $false, ValueFromPipeline = $true)] [String]$ApiKey ) if ($ApiKey) { $SecApiKey = ConvertTo-SecureString $ApiKey -AsPlainText -Force } else { $SecApiKey = Read-Host -Prompt 'Please enter your Hudu API key, you can obtain it from https://your-hudu-domain/admin/api_keys:' -AsSecureString } Set-Variable -Name 'Int_HuduAPIKey' -Value $SecApiKey -Visibility Private -Scope script -Force if ($script:Int_HuduBaseURL) { [version]$version = (Get-HuduAppInfo).version if ($version -lt $script:HuduRequiredVersion) { Write-Warning "A connection error occured or Hudu version is below $script:HuduRequiredVersion" } } } #EndRegion './Public/New-HuduAPIKey.ps1' 26 #Region './Public/New-HuduArticle.ps1' 0 function New-HuduArticle { [CmdletBinding(SupportsShouldProcess)] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Parameter(Mandatory = $true)] [String]$Content, [Alias('folder_id')] [Int]$FolderId = '', [Alias('company_id')] [Int]$CompanyId = '' ) $Article = [ordered]@{article = [ordered]@{} } $Article.article.add('name', $Name) $Article.article.add('content', $Content) if ($FolderId) { $Article.article.add('folder_id', $FolderId) } if ($CompanyId) { $Article.article.add('company_id', $CompanyId) } $JSON = $Article | ConvertTo-Json -Depth 10 if ($PSCmdlet.ShouldProcess($Name)) { $Response = Invoke-HuduRequest -Method post -Resource '/api/v1/articles' -Body $JSON } $Response } #EndRegion './Public/New-HuduArticle.ps1' 35 #Region './Public/New-HuduAsset.ps1' 0 function New-HuduAsset { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Alias("asset_layout_id")] [Parameter(Mandatory = $true)] [Int]$AssetLayoutId, [Array]$Fields, [Alias("primary_serial")] [string]$PrimarySerial, [Alias("primary_mail")] [string]$PrimaryMail, [Alias("primary_model")] [string]$PrimaryModel, [Alias("primary_manufacturer")] [string]$PrimaryManufacturer ) $Asset = [ordered]@{asset = [ordered]@{} } $Asset.asset.add('name', $Name) $Asset.asset.add('asset_layout_id', $AssetLayoutId) if ($PrimarySerial) { $Asset.asset.add('primary_serial', $PrimarySerial) } if ($PrimaryMail) { $Asset.asset.add('primary_mail', $PrimaryMail) } if ($PrimaryModel) { $Asset.asset.add('primary_model', $PrimaryModel) } if ($PrimaryManufacturer) { $Asset.asset.add('primary_manufacturer', $PrimaryManufacturer) } if ($Fields) { $Asset.asset.add('custom_fields', $Fields) } $JSON = $Asset | convertto-json -Depth 10 $Response = Invoke-HuduRequest -Method post -Resource "/api/v1/companies/$CompanyId/assets" -body $JSON $Response } #EndRegion './Public/New-HuduAsset.ps1' 55 #Region './Public/New-HuduAssetLayout.ps1' 0 function New-HuduAssetLayout { [CmdletBinding()] # This will silence the warning for variables with Password in their name. [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Parameter(Mandatory = $true)] [String]$Icon, [Parameter(Mandatory = $true)] [String]$Color, [Alias('icon_color')] [Parameter(Mandatory = $true)] [String]$IconColor, [Alias('include_passwords')] [bool]$IncludePasswords = '', [Alias('include_photos')] [bool]$IncludePhotos = '', [Alias('include_comments')] [bool]$IncludeComments = '', [Alias('include_files')] [bool]$IncludeFiles = '', [Alias('password_types')] [String]$PasswordTypes = '', [Parameter(Mandatory = $true)] [system.collections.generic.list[hashtable]]$Fields, [bool]$Active = $true ) foreach ($field in $fields) { if ($field.show_in_list) { $field.show_in_list = [System.Convert]::ToBoolean($field.show_in_list) } else { $field.remove('show_in_list') } if ($field.required) { $field.required = [System.Convert]::ToBoolean($field.required) } else { $field.remove('required') } if ($field.expiration) { $field.expiration = [System.Convert]::ToBoolean($field.expiration) } else { $field.remove('expiration') } } $AssetLayout = [ordered]@{asset_layout = [ordered]@{} } $AssetLayout.asset_layout.add('name', $Name) $AssetLayout.asset_layout.add('icon', $Icon) $AssetLayout.asset_layout.add('color', $Color) $AssetLayout.asset_layout.add('icon_color', $IconColor) $AssetLayout.asset_layout.add('fields', $Fields) $AssetLayout.asset_layout.add('active', $Active) if ($IncludePasswords) { $AssetLayout.asset_layout.add('include_passwords', [System.Convert]::ToBoolean($IncludePasswords)) } if ($IncludePhotos) { $AssetLayout.asset_layout.add('include_photos', [System.Convert]::ToBoolean($IncludePhotos)) } if ($IncludeComments) { $AssetLayout.asset_layout.add('include_comments', [System.Convert]::ToBoolean($IncludeComments)) } if ($IncludeFiles) { $AssetLayout.asset_layout.add('include_files', [System.Convert]::ToBoolean($IncludeFiles)) } if ($PasswordTypes) { $AssetLayout.asset_layout.add('password_types', $PasswordTypes) } $JSON = $AssetLayout | ConvertTo-Json -Depth 10 Write-Verbose $JSON $Response = Invoke-HuduRequest -Method post -Resource '/api/v1/asset_layouts' -Body $JSON $Response } #EndRegion './Public/New-HuduAssetLayout.ps1' 75 #Region './Public/New-HuduBaseURL.ps1' 0 function New-HuduBaseURL { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function')] [CmdletBinding()] Param ( [Parameter(Mandatory = $false, ValueFromPipeline = $true)] [String] $BaseURL ) if (!$BaseURL) { $BaseURL = Read-Host -Prompt 'Please enter your Hudu Base URL with no trailing /, for example https://demo.huducloud.com :' } Set-Variable -Name 'Int_HuduBaseURL' -Value $BaseURL -Visibility Private -Scope script -Force if ($script:Int_HuduAPIKey) { [version]$Version = (Get-HuduAppInfo).version if ($Version -lt $script:HuduRequiredVersion) { Write-Warning "A connection error occured or Hudu version is below $script:HuduRequiredVersion" } } } #EndRegion './Public/New-HuduBaseURL.ps1' 23 #Region './Public/New-HuduCompany.ps1' 0 function New-HuduCompany { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [String]$Nickname = '', [Alias("company_type")] [String]$CompanyType = '', [Alias('address_line_1')] [String]$AddressLine1 = '', [Alias('address_line_2')] [String]$AddressLine2 = '', [String]$City = '', [String]$State = '', [Alias('PostalCode', 'PostCode')] [String]$Zip = '', [Alias('country_name')] [String]$CountryName = '', [Alias('phone_number')] [String]$PhoneNumber = '', [Alias('fax_number')] [String]$FaxNumber = '', [String]$Website = '', [Alias('id_number')] [String]$IdNumber = '', [String]$Notes = '' ) $Company = [ordered]@{company = [ordered]@{} } $Company.company.add('name', $Name) if (-not ([string]::IsNullOrEmpty($Nickname))) { $Company.company.add('nickname', $Nickname) } if (-not ([string]::IsNullOrEmpty($Nickname))) { $Company.company.add('company_type', $CompanyType) } if (-not ([string]::IsNullOrEmpty($AddressLine1))) { $Company.company.add('address_line_1', $AddressLine1) } if (-not ([string]::IsNullOrEmpty($AddressLine2))) { $Company.company.add('address_line_2', $AddressLine2) } if (-not ([string]::IsNullOrEmpty($City))) { $Company.company.add('city', $City) } if (-not ([string]::IsNullOrEmpty($State))) { $Company.company.add('state', $State) } if (-not ([string]::IsNullOrEmpty($Zip))) { $Company.company.add('zip', $Zip) } if (-not ([string]::IsNullOrEmpty($CountryName))) { $Company.company.add('country_name', $CountryName) } if (-not ([string]::IsNullOrEmpty($PhoneNumber))) { $Company.company.add('phone_number', $PhoneNumber) } if (-not ([string]::IsNullOrEmpty($FaxNumber))) { $Company.company.add('fax_number', $FaxNumber) } if (-not ([string]::IsNullOrEmpty($Website))) { $Company.company.add('website', $Website) } if (-not ([string]::IsNullOrEmpty($IdNumber))) { $Company.company.add('id_number', $IdNumber) } if (-not ([string]::IsNullOrEmpty($Notes))) { $Company.company.add('notes', $Notes) } $JSON = $Company | ConvertTo-Json -Depth 10 Write-Verbose $JSON $Response = Invoke-HuduRequest -Method post -Resource '/api/v1/companies' -Body $JSON $Response } #EndRegion './Public/New-HuduCompany.ps1' 55 #Region './Public/New-HuduFolder.ps1' 0 function New-HuduFolder { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [String]$Icon = '', [String]$Description = '', [Alias("parent_folder_id")] [Int]$ParentFolderId = '', [Alias("company_id")] [Int]$CompanyId = '' ) $Folder = [ordered]@{folder = [ordered]@{} } $Folder.folder.add('name', $Name) if ($Icon) { $Folder.folder.add('icon', $Icon) } if ($Description) { $Folder.folder.add('description', $Description) } if ($ParentFolderId) { $Folder.folder.add('parent_folder_id', $ParentFolderId) } if ($CompanyId) { $Folder.folder.add('company_id', $CompanyId) } $JSON = $Folder | convertto-json $Response = Invoke-HuduRequest -Method post -Resource "/api/v1/folders" -body $JSON $Response } #EndRegion './Public/New-HuduFolder.ps1' 41 #Region './Public/New-HuduPassword.ps1' 0 function New-HuduPassword { [CmdletBinding()] # This will silence the warning for variables with Password in their name. [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Alias("passwordable_type")] [String]$PasswordableType = '', [Alias("passwordable_id")] [int]$PasswordableId = '', [Alias("in_portal")] [Bool]$InPortal = $false, [Parameter(Mandatory = $true)] [String]$Password = '', [Alias("otp_secret")] [string]$OTPSecret = '', [String]$URL = '', [String]$Username = '', [String]$Description = '', [Alias("password_type")] [String]$PasswordType = '' ) $AssetPassword = [ordered]@{asset_password = [ordered]@{} } $AssetPassword.asset_password.add('name', $Name) $AssetPassword.asset_password.add('company_id', $CompanyId) $AssetPassword.asset_password.add('password', $Password) $AssetPassword.asset_password.add('in_portal', $InPortal) if ($PasswordableType) { $AssetPassword.asset_password.add('passwordable_type', $PasswordableType) } if ($PasswordableId) { $AssetPassword.asset_password.add('passwordable_id', $PasswordableId) } if ($OTPSecret) { $AssetPassword.asset_password.add('otp_secret', $OTPSecret) } if ($URL) { $AssetPassword.asset_password.add('url', $URL) } if ($Username) { $AssetPassword.asset_password.add('username', $Username) } if ($Description) { $AssetPassword.asset_password.add('description', $Description) } if ($PasswordType) { $AssetPassword.asset_password.add('password_type', $PasswordType) } $JSON = $AssetPassword | ConvertTo-Json -Depth 10 $Response = Invoke-HuduRequest -Method post -Resource "/api/v1/asset_passwords" -body $JSON $Response } #EndRegion './Public/New-HuduPassword.ps1' 69 #Region './Public/New-HuduPublicPhoto.ps1' 0 function New-HuduPublicPhoto { param( [Parameter(Mandatory)][string]$FilePath, [int]$record_id, [string]$record_type ) $form = @{ photo = Get-item $FilePath } if ($record_id) {$form['record_id'] = $record_id} if ($record_type) {$form['record_type'] = $record_type} $UploadedPhoto = Invoke-HuduRequest -Method POST -Resource "/api/v1/public_photos" -Form $form return $UploadedPhoto } #EndRegion './Public/New-HuduPublicPhoto.ps1' 20 #Region './Public/New-HuduRelation.ps1' 0 function New-HuduRelation { [CmdletBinding()] Param ( [String]$Description, [Parameter(Mandatory = $true)] [ValidateSet('Asset','Website','Procedure','AssetPassword','Company','Article')] [Alias("fromable_type")] [String]$FromableType, [Alias("fromable_id")] [int]$FromableID, [Alias("toable_type")] [String]$ToableType, [Alias("toable_id")] [int]$ToableID, [Alias("is_inverse")] [string]$ISInverse ) $Relation = [ordered]@{relation = [ordered]@{} } $Relation.relation.add('fromable_type', $FromableType) $Relation.relation.add('fromable_id', $FromableID) $Relation.relation.add('toable_type', $ToableType) $Relation.relation.add('toable_id', $ToableID) if ($Description) { $Relation.relation.add('description', $Description) } if ($ISInverse) { $Relation.relation.add('is_inverse', $ISInverse) } $JSON = $Relation | convertto-json -Depth 100 $Response = Invoke-HuduRequest -Method post -Resource "/api/v1/relations" -body $JSON $Response } #EndRegion './Public/New-HuduRelation.ps1' 42 #Region './Public/New-HuduWebsite.ps1' 0 function New-HuduWebsite { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [String]$Notes = '', [String]$Paused = '', [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Alias("disable_dns")] [String]$DisableDNS = '', [Alias("disable_ssl")] [String]$DisableSSL = '', [Alias("disable_whois")] [String]$DisableWhois = '' ) $Website = [ordered]@{website = [ordered]@{} } $Website.website.add('name', $Name) if ($Notes) { $Website.website.add('notes', $Notes) } if ($Paused) { $Website.website.add('paused', $Paused) } $Website.website.add('company_id', $CompanyId) if ($DisableDNS) { $Website.website.add('disable_dns', $DisableDNS) } if ($DisableSSL) { $Website.website.add('disable_ssl', $DisableSSL) } if ($DisableWhois) { $Website.website.add('disable_whois', $DisableWhois) } $JSON = $Website | ConvertTo-Json $Response = Invoke-HuduRequest -Method post -Resource "/api/v1/websites" -body $JSON $Response } #EndRegion './Public/New-HuduWebsite.ps1' 52 #Region './Public/Remove-HuduAPIKey.ps1' 0 function Remove-HuduAPIKey { [CmdletBinding()] Param() Set-Variable -Name "Int_HuduAPIKey" -Value $null -Visibility Private -Scope script -Force } #EndRegion './Public/Remove-HuduAPIKey.ps1' 6 #Region './Public/Remove-HuduArticle.ps1' 0 function Remove-HuduArticle { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id ) $Response = Invoke-HuduRequest -Method delete -Resource "/api/v1/articles/$Id" $Response } #EndRegion './Public/Remove-HuduArticle.ps1' 13 #Region './Public/Remove-HuduAsset.ps1' 0 function Remove-HuduAsset { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId ) $Response = Invoke-HuduRequest -Method delete -Resource "/api/v1/companies/$CompanyId/assets/$Id" $Response } #EndRegion './Public/Remove-HuduAsset.ps1' 16 #Region './Public/Remove-HuduBaseURL.ps1' 0 function Remove-HuduBaseURL { [CmdletBinding()] Param() Set-Variable -Name "Int_HuduBaseURL" -Value $null -Visibility Private -Scope script -Force } #EndRegion './Public/Remove-HuduBaseURL.ps1' 6 #Region './Public/Remove-HuduMagicDash.ps1' 0 function Remove-HuduMagicDash { [CmdletBinding()] Param ( [String]$Title = '', [Alias("company_name")] [String]$CompanyName = '', [String]$Id = '' ) if ($id) { $null = Invoke-HuduRequest -Method delete -Resource "/api/v1/magic_dash/$Id" } else { if ($Title -and $CompanyName) { $MagicDash = @{} $MagicDash.add('title', $Title) $MagicDash.add('company_name', $CompanyName) $JSON = $MagicDash | convertto-json $null = Invoke-HuduRequest -Method delete -Resource "/api/v1/magic_dash" -body $JSON } else { Write-Host "ERROR: Please set title and company_name" -ForegroundColor Red } } } #EndRegion './Public/Remove-HuduMagicDash.ps1' 32 #Region './Public/Remove-HuduPassword.ps1' 0 function Remove-HuduPassword { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id ) $Response = Invoke-HuduRequest -Method delete -Resource "/api/v1/asset_passwords/$Id" $Response } #EndRegion './Public/Remove-HuduPassword.ps1' 13 #Region './Public/Remove-HuduRelation.ps1' 0 function Remove-HuduRelation { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id ) $Response = Invoke-HuduRequest -Method delete -Resource "/api/v1/relations/$Id" $Response } #EndRegion './Public/Remove-HuduRelation.ps1' 13 #Region './Public/Remove-HuduWebsite.ps1' 0 function Remove-HuduWebsite { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id ) $Response = Invoke-HuduRequest -Method delete -Resource "/api/v1/websites/$Id" $Response } #EndRegion './Public/Remove-HuduWebsite.ps1' 13 #Region './Public/Set-HuduArticle.ps1' 0 function Set-HuduArticle { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Parameter(Mandatory = $true)] [String]$Content, [Alias("folder_id")] [Int]$FolderId = '', [Alias("company_id")] [Int]$CompanyId = '', [Alias("article_id", "id")] [Parameter(Mandatory = $true)] [Int]$ArticleId ) $Article = [ordered]@{article = [ordered]@{} } $Article.article.add('name', $Name) $Article.article.add('content', $Content) if ($FolderId) { $Article.article.add('folder_id', $FolderId) } if ($CompanyId) { $Article.article.add('company_id', $CompanyId) } $JSON = $Article | ConvertTo-Json -Depth 10 $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/articles/$ArticleId" -body $JSON $Response } #EndRegion './Public/Set-HuduArticle.ps1' 37 #Region './Public/Set-HuduArticleArchive.ps1' 0 function Set-HuduArticleArchive { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [Bool]$Archive ) if ($Archive) { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/articles/$Id/archive" } else { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/articles/$Id/unarchive" } $Response } #EndRegion './Public/Set-HuduArticleArchive.ps1' 17 #Region './Public/Set-HuduAsset.ps1' 0 function Set-HuduAsset { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Name, [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Alias("asset_layout_id")] [Parameter(Mandatory = $true)] [Int]$AssetLayoutId, [Array]$Fields, [Alias("asset_id")] [Parameter(Mandatory = $true)] [Int]$AssetId, [Alias("primary_serial")] [string]$PrimarySerial, [Alias("primary_mail")] [string]$PrimaryMail, [Alias("primary_model")] [string]$PrimaryModel, [Alias("primary_manufacturer")] [string]$PrimaryManufacturer ) $Asset = [ordered]@{asset = [ordered]@{} } $Asset.asset.add('name', $Name) $Asset.asset.add('asset_layout_id', $AssetLayoutId) if ($PrimarySerial) { $Asset.asset.add('primary_serial', $PrimarySerial) } if ($PrimaryMail) { $Asset.asset.add('primary_mail', $PrimaryMail) } if ($PrimaryModel) { $Asset.asset.add('primary_model', $PrimaryModel) } if ($PrimaryManufacturer) { $Asset.asset.add('primary_manufacturer', $PrimaryManufacturer) } if ($Fields) { $Asset.asset.add('custom_fields', $Fields) } $JSON = $Asset | ConvertTo-Json -Depth 10 $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/companies/$CompanyId/assets/$AssetId" -body $JSON $Response } #EndRegion './Public/Set-HuduAsset.ps1' 58 #Region './Public/Set-HuduAssetArchive.ps1' 0 function Set-HuduAssetArchive { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Parameter(Mandatory = $true)] [Bool]$Archive ) if ($Archive) { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/companies/$CompanyId/assets/$Id/archive" } else { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/companies/$CompanyId/assets/$Id/unarchive" } $Response } #EndRegion './Public/Set-HuduAssetArchive.ps1' 20 #Region './Public/Set-HuduAssetLayout.ps1' 0 function Set-HuduAssetLayout { [CmdletBinding()] # This will silence the warning for variables with Password in their name. [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [String]$Name, [Parameter(Mandatory = $true)] [String]$Icon, [Parameter(Mandatory = $true)] [String]$Color, [Alias("icon_color")] [Parameter(Mandatory = $true)] [String]$IconColor, [Alias("include_passwords")] [bool]$IncludePasswords = '', [Alias("include_photos")] [bool]$IncludePhotos = '', [Alias("include_comments")] [bool]$IncludeComments = '', [Alias("include_files")] [bool]$IncludeFiles = '', [Alias("password_types")] [String]$PasswordTypes = '', [Parameter(Mandatory = $true)] [array]$Fields, [bool]$Active = $true ) foreach ($Field in $Fields) { $Field.show_in_list = [System.Convert]::ToBoolean($Field.show_in_list) $Field.required = [System.Convert]::ToBoolean($Field.required) $Field.expiration = [System.Convert]::ToBoolean($Field.expiration) } $AssetLayout = [ordered]@{asset_layout = [ordered]@{} } $AssetLayout.asset_layout.add('name', $Name) $AssetLayout.asset_layout.add('icon', $Icon) $AssetLayout.asset_layout.add('color', $Color) $AssetLayout.asset_layout.add('icon_color', $IconColor) $AssetLayout.asset_layout.add('fields', $Fields) $AssetLayout.asset_layout.add('active', $Active) if ($IncludePasswords) { $AssetLayout.asset_layout.add('include_passwords', [System.Convert]::ToBoolean($IncludePasswords)) } if ($IncludePhotos) { $AssetLayout.asset_layout.add('include_photos', [System.Convert]::ToBoolean($IncludePhotos)) } if ($IncludeComments) { $AssetLayout.asset_layout.add('include_comments', [System.Convert]::ToBoolean($IncludeComments)) } if ($IncludeFiles) { $AssetLayout.asset_layout.add('include_files', [System.Convert]::ToBoolean($IncludeFiles)) } if ($PasswordTypes) { $AssetLayout.asset_layout.add('password_types', $PasswordTypes) } $JSON = $AssetLayout | convertto-json -Depth 10 $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/asset_layouts/$Id" -body $JSON $Response } #EndRegion './Public/Set-HuduAssetLayout.ps1' 75 #Region './Public/Set-HuduCompany.ps1' 0 function Set-HuduCompany { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [String]$Name, [String]$Nickname = '', [Alias("company_type")] [String]$CompanyType = '', [Alias("address_line_1")] [String]$AddressLine1 = '', [Alias("address_line_2")] [String]$AddressLine2 = '', [String]$City = '', [String]$State = '', [Alias("PostalCode", "PostCode")] [String]$Zip = '', [Alias("country_name")] [String]$CountryName = '', [Alias("phone_number")] [String]$PhoneNumber = '', [Alias("fax_number")] [String]$FaxNumber = '', [String]$Website = '', [Alias("id_number")] [String]$IdNumber = '', [Alias("parent_company_id")] [Int]$ParentCompanyId, [String]$Notes = '' ) $Company = [ordered]@{company = [ordered]@{} } $Company.company.add('name', $Name) $Company.company.add('nickname', $Nickname) $Company.company.add('company_type', $CompanyType) $Company.company.add('address_line_1', $AddressLine1) $Company.company.add('address_line_2', $AddressLine2) $Company.company.add('city', $City) $Company.company.add('state', $State) $Company.company.add('zip', $Zip) $Company.company.add('country_name', $CountryName) $Company.company.add('phone_number', $PhoneNumber) $Company.company.add('fax_number', $FaxNumber) $Company.company.add('website', $Website) $Company.company.add('id_number', $IdNumber) $Company.company.add('parent_company_id', $ParentCompanyId) $Company.company.add('notes', $Notes) $JSON = $Company | ConvertTo-Json -Depth 10 $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/companies/$Id" -body $JSON $Response } #EndRegion './Public/Set-HuduCompany.ps1' 58 #Region './Public/Set-HuduCompanyArchive.ps1' 0 function Set-HuduCompanyArchive { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [Bool]$Archive ) if ($Archive -eq $true) { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/companies/$Id/archive" } else { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/companies/$Id/unarchive" } $Response } #EndRegion './Public/Set-HuduCompanyArchive.ps1' 17 #Region './Public/Set-HuduFolder.ps1' 0 function Set-HuduFolder { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [String]$Name, [String]$Icon = '', [String]$Description = '', [Alias("parent_folder_id")] [Int]$ParentFolderId = '', [Alias("company_id")] [Int]$CompanyId = '' ) $Folder = [ordered]@{folder = [ordered]@{} } $Folder.folder.add('name', $Name) if ($icon) { $Folder.folder.add('icon', $Icon) } if ($Description) { $Folder.folder.add('description', $Description) } if ($ParentFolderId) { $Folder.folder.add('parent_folder_id', $ParentFolderId) } if ($CompanyId) { $Folder.folder.add('company_id', $CompanyId) } $JSON = $Folder | convertto-json $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/folders/$Id" -body $JSON $Response } #EndRegion './Public/Set-HuduFolder.ps1' 42 #Region './Public/Set-HuduIntegrationMatcher.ps1' 0 function Set-HuduIntegrationMatcher { [CmdletBinding()] Param ( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [String]$Id, [Parameter(ParameterSetName = 'AcceptSuggestedMatch')] [switch]$AcceptSuggestedMatch, [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'SetCompanyId')] [Alias('company_id')] [String]$CompanyId, [Parameter(ValueFromPipelineByPropertyName = $true)] [Alias('potential_company_id')] [String]$PotentialCompanyId, [Parameter(ValueFromPipelineByPropertyName = $true)] [Alias('sync_id')] [String]$SyncId, [Parameter(ValueFromPipelineByPropertyName = $true)] [String]$Identifier ) Process { $Matcher = [ordered]@{matcher = [ordered]@{} } if ($AcceptSuggestedMatch) { $Matcher.matcher.add('company_id', $PotentialCompanyId) | Out-Null } else { $Matcher.matcher.add('company_id', $CompanyId) | Out-Null } if ($PotentialCompanyId) { $Matcher.matcher.add('potential_company_id', $PotentialCompanyId) | Out-Null } if ($SyncId) { $Matcher.matcher.add('sync_id', $SyncId) | Out-Null } if ($Identifier) { $Matcher.matcher.add('identifier', $identifier) | Out-Null } $JSON = $Matcher | ConvertTo-Json -Depth 10 $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/matchers/$Id" -Body $JSON $Response } } #EndRegion './Public/Set-HuduIntegrationMatcher.ps1' 52 #Region './Public/Set-HuduMagicDash.ps1' 0 function Set-HuduMagicDash { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [String]$Title, [Alias("company_name")] [Parameter(Mandatory = $true)] [String]$CompanyName, [Parameter(Mandatory = $true)] [String]$Message, [String]$Icon = '', [Alias("image_url")] [String]$ImageURL = '', [Alias("content_link")] [String]$ContentLink = '', [String]$Content = '', [String]$Shade = '' ) if ($Icon -and $ImageURL) { write-error ("You can only use one of icon or image URL") exit 1 } if ($content_link -and $content) { write-error ("You can only use one of content or content_link") exit 1 } $MagicDash = [ordered]@{} if ($Title) { $MagicDash.add('title', $Title) } if ($CompanyName) { $MagicDash.add('company_name', $CompanyName) } if ($Message) { $MagicDash.add('message', $Message) } if ($Icon) { $MagicDash.add('icon', $Icon) } if ($ImageURL) { $MagicDash.add('image_url', $ImageURL) } if ($ContentLink) { $MagicDash.add('content_link', $ContentLink) } if ($Content) { $MagicDash.add('content', $Content) } if ($Shade) { $MagicDash.add('shade', $Shade) } $JSON = $MagicDash | convertto-json $Response = Invoke-HuduRequest -Method post -Resource "/api/v1/magic_dash" -body $JSON $Response } #EndRegion './Public/Set-HuduMagicDash.ps1' 70 #Region './Public/Set-HuduPassword.ps1' 0 function Set-HuduPassword { [CmdletBinding()] # This will silence the warning for variables with Password in their name. [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [String]$Name, [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Alias("passwordable_type")] [String]$PasswordableType = '', [Alias("passwordable_id")] [int]$PasswordableId = '', [Alias("in_portal")] [Bool]$InPortal = $false, [Parameter(Mandatory = $true)] [String]$Password = '', [Alias("otp_secret")] [string]$OTPSecret = '', [String]$URL = '', [String]$Username = '', [String]$Description = '', [Alias("password_type")] [String]$PasswordType = '' ) $AssetPassword = [ordered]@{asset_password = [ordered]@{} } $AssetPassword.asset_password.add('name', $Name) $AssetPassword.asset_password.add('company_id', $CompanyId) $AssetPassword.asset_password.add('password', $Password) $AssetPassword.asset_password.add('in_portal', $InPortal) if ($PasswordableType) { $AssetPassword.asset_password.add('passwordable_type', $PasswordableType) } if ($PasswordableId) { $AssetPassword.asset_password.add('passwordable_id', $PasswordableId) } if ($OTPSecret) { $AssetPassword.asset_password.add('otp_secret', $OTPSecret) } if ($URL) { $AssetPassword.asset_password.add('url', $URL) } if ($Username) { $AssetPassword.asset_password.add('username', $Username) } if ($Description) { $AssetPassword.asset_password.add('description', $Description) } if ($PasswordType) { $AssetPassword.asset_password.add('password_type', $PasswordType) } $JSON = $AssetPassword | convertto-json -Depth 10 $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/asset_passwords/$Id" -body $JSON $Response } #EndRegion './Public/Set-HuduPassword.ps1' 71 #Region './Public/Set-HuduPasswordArchive.ps1' 0 function Set-HuduPasswordArchive { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [Bool]$Archive ) if ($Archive) { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/asset_passwords/$Id/archive" } else { $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/asset_passwords/$Id/unarchive" } $Response } #EndRegion './Public/Set-HuduPasswordArchive.ps1' 17 #Region './Public/Set-HuduWebsite.ps1' 0 function Set-HuduWebsite { [CmdletBinding()] Param ( [Parameter(Mandatory = $true)] [Int]$Id, [Parameter(Mandatory = $true)] [String]$Name, [String]$Notes = '', [String]$Paused = '', [Alias("company_id")] [Parameter(Mandatory = $true)] [Int]$CompanyId, [Alias("disable_dns")] [String]$DisableDNS = '', [Alias("disable_ssl")] [String]$DisableSSL = '', [Alias("disable_whois")] [String]$DisableWhois = '' ) $Website = [ordered]@{website = [ordered]@{} } $Website.website.add('name', $Name) if ($Notes) { $Website.website.add('notes', $Notes) } if ($Paused) { $Website.website.add('paused', $Paused) } $Website.website.add('company_id', $companyid) if ($DisableDNS) { $Website.website.add('disable_dns', $DisableDNS) } if ($DisableSSL) { $Website.website.add('disable_ssl', $DisableSSL) } if ($DisableWhois) { $Website.website.add('disable_whois', $DisableWhois) } $JSON = $Website | convertto-json $Response = Invoke-HuduRequest -Method put -Resource "/api/v1/websites/$Id" -body $JSON $Response } #EndRegion './Public/Set-HuduWebsite.ps1' 54 |