diff --git a/Docs/Get-HuduExports.md b/Docs/Get-HuduExports.md new file mode 100644 index 0000000..5c4194d --- /dev/null +++ b/Docs/Get-HuduExports.md @@ -0,0 +1,75 @@ +--- +external help file: HuduAPI-help.xml +Module Name: HuduAPI +online version: +schema: 2.0.0 +--- + +# Get-HuduExports + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Get-HuduExports [[-id] ] [-ProgressAction ] [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -id +{{ Fill id Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Docs/Save-HuduExports.md b/Docs/Save-HuduExports.md new file mode 100644 index 0000000..ac816e0 --- /dev/null +++ b/Docs/Save-HuduExports.md @@ -0,0 +1,122 @@ +--- +external help file: HuduAPI-help.xml +Module Name: HuduAPI +online version: +schema: 2.0.0 +--- + +# Save-HuduExports + +## SYNOPSIS +{{ Fill in the Synopsis }} + +## SYNTAX + +``` +Save-HuduExports [[-Id] ] [[-OutDir] ] [-ProgressAction ] [-WhatIf] [-Confirm] + [] +``` + +## DESCRIPTION +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Id +{{ Fill Id Description }} + +```yaml +Type: Int64 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutDir +{{ Fill OutDir Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/Docs/Set-HuduPublicPhoto.md b/Docs/Set-HuduPublicPhoto.md new file mode 100644 index 0000000..012472f --- /dev/null +++ b/Docs/Set-HuduPublicPhoto.md @@ -0,0 +1,134 @@ +--- +external help file: HuduAPI-help.xml +Module Name: HuduAPI +online version: +schema: 2.0.0 +--- + +# Set-HuduPublicPhoto + +## SYNOPSIS +Update the associated record type and ID for a specific public photo. + +## SYNTAX + +``` +Set-HuduPublicPhoto [-id] [-RecordId] [-RecordType] + [-ProgressAction ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Reassociate a public photo object. +Backward Compatibility: This endpoint still accepts numeric IDs in the path parameter for existing integrations, but responses will include the new slug-based ID format. + +## EXAMPLES + +### EXAMPLE 1 +``` +Set-HuduPublicPhoto -id 123 -RecordId 1 -RecordType 'asset' +Set-HuduPublicPhoto -id 432 -RecordId 7 -RecordType 'article' +``` + +## PARAMETERS + +### -id +The id of the public photo to update + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: photo_id + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RecordId +Record id to associate with the photo + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: record_id + +Required: True +Position: 2 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RecordType +Record type to associate with the photo + +```yaml +Type: String +Parameter Sets: (All) +Aliases: record_type + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/HuduAPI/HuduAPI.psd1 b/HuduAPI/HuduAPI.psd1 index 6be89e1..ba50600 100644 --- a/HuduAPI/HuduAPI.psd1 +++ b/HuduAPI/HuduAPI.psd1 @@ -83,6 +83,7 @@ 'Get-HuduCompanyFolders', 'Get-HuduFolderCleanName', 'Get-HuduExpirations', + 'Get-HuduExports', 'Get-HuduFolderMap', 'Get-HuduFolders', 'Get-HuduGroups', @@ -161,6 +162,7 @@ 'Remove-HuduVLAN', 'Remove-HuduVLANZone', 'Remove-HuduWebsite', + 'Save-HuduExports', 'Set-HuduArticle', 'Set-HuduArticleArchive', 'Set-HuduAsset', @@ -180,6 +182,7 @@ 'Set-HuduPassword', 'Set-HuduPasswordFolder', 'Set-HuduPasswordArchive', + 'Set-HuduPublicPhoto', 'Set-HuduVLAN', 'Set-HuduVLANZone', 'Set-HuduRackStorageItem', @@ -244,4 +247,4 @@ # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' -} +} \ No newline at end of file diff --git a/HuduAPI/Public/Get-HuduExports.ps1 b/HuduAPI/Public/Get-HuduExports.ps1 new file mode 100644 index 0000000..45a843c --- /dev/null +++ b/HuduAPI/Public/Get-HuduExports.ps1 @@ -0,0 +1,11 @@ +function Get-HuduExports { + [CmdletBinding()] + param( + [int]$id + ) + if ($null -ne $id -and $id -ge 1){ + Invoke-HuduRequest -Method 'GET' -Resource "/api/v1/exports/$id" + } else { + Invoke-HuduRequest -Method 'GET' -Resource '/api/v1/exports' + } +} \ No newline at end of file diff --git a/HuduAPI/Public/Save-HuduExports.ps1 b/HuduAPI/Public/Save-HuduExports.ps1 new file mode 100644 index 0000000..43e8663 --- /dev/null +++ b/HuduAPI/Public/Save-HuduExports.ps1 @@ -0,0 +1,40 @@ + +function Save-HuduExports { + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter()] + [long]$Id, + [Parameter()] + [string]$OutDir = '.' + ) + + $OutDir = [string]::IsNullOrWhiteSpace($OutDir) ? (Get-Location).Path : $OutDir + $OutDir = (New-Item -ItemType Directory -Path $OutDir -Force).FullName + $exports = $(if ($null -ne $Id) {@(Get-HuduExports -id $id)} else {@(Get-HuduExports)}) + + if (-not $exports -or $exports.Count -eq 0) {Write-Warning "No exports available."; return;} + $HuduAPIKey = Get-HuduApiKey + $Headers = @{'x-api-key' = (New-Object PSCredential 'user', $HuduAPIKey).GetNetworkCredential().Password;} + + $files = @(); $fileIDX = 0; + foreach ($export in $exports) { + $fileIDX++; $downloadedFile = $null; + $fileName = $export.file_name ?? "export-$($export.id)$(if ($export.is_pdf) { '.pdf' } else { '.csv' })" + + if (-not $export.download_url -or [string]::isnullorempty($export.download_url)) { + Write-Warning "Export id $($export.id) has no download_url yet (status=$($export.status)). Skipping." + write-host "$($($export | convertto-json -depth 99).ToSTring())" + continue + } + + $outPath = Join-Path $OutDir $fileName + + if ($PSCmdlet.ShouldProcess($outPath, "Download export id $exId")) { + Invoke-WebRequest -Uri $export.download_url -headers $headers -OutFile $outPath -MaximumRedirection 10 | Out-Null + } + $downloadedFile = $(Get-Item -LiteralPath $outPath) + Write-Host "downloaded $fileName to $($downloadedFile) ($fileIDX of $($exports.count))" + $files+=$($downloadedFile) + } + return $files +} diff --git a/HuduAPI/Public/Set-HuduPasswordFolder.ps1 b/HuduAPI/Public/Set-HuduPasswordFolder.ps1 index 81a6291..9e2fa56 100644 --- a/HuduAPI/Public/Set-HuduPasswordFolder.ps1 +++ b/HuduAPI/Public/Set-HuduPasswordFolder.ps1 @@ -36,7 +36,10 @@ function Set-HuduPasswordFolder { [string]$Name, [string]$Description, [ValidateSet("all_users","specific")][String]$Security, - [array]$AllowedGroups) + [array]$AllowedGroups, + [Alias('company_id')] + [int]$CompanyID + ) $passwordFolder = Get-HuduPasswordFolders -Id $Id @@ -47,6 +50,9 @@ function Set-HuduPasswordFolder { if ($passwordFolder.company_id){ $updatePasswordFolder.company_id = $passwordFolder.company_id } + + if ($PSBoundParameters.ContainsKey('CompanyID')) { $passwordFolder.company_id = $CompanyID } + if (($AllowedGroups -and $AllowedGroups -ne $passwordFolder.allowed_groups) -or ($security -and $security -eq "specific")){ $updatePasswordFolder["security"] = $security $allGroups = $(Get-HuduGroups).id @@ -67,12 +73,10 @@ function Set-HuduPasswordFolder { try { - $res = Invoke-HuduRequest -Method POST -Resource "/api/v1/password_folders" -Body $(@{password_folder = $updatePasswordFolder} | ConvertTo-Json -Depth 10) + $res = Invoke-HuduRequest -Method PUT -Resource "/api/v1/password_folders/$ID" -Body $(@{password_folder = $passwordFolder} | ConvertTo-Json -Depth 10) return $res } catch { Write-Warning "Failed to create new password folder '$Name'" return $null } } - - diff --git a/HuduAPI/Public/Set-HuduPublicPhoto.ps1 b/HuduAPI/Public/Set-HuduPublicPhoto.ps1 new file mode 100644 index 0000000..3ae0b7d --- /dev/null +++ b/HuduAPI/Public/Set-HuduPublicPhoto.ps1 @@ -0,0 +1,54 @@ +function Set-HuduPublicPhoto { + <# + .SYNOPSIS + Update the associated record type and ID for a specific public photo. + + .DESCRIPTION + Reassociate a public photo object. Backward Compatibility: This endpoint still accepts numeric IDs in the path parameter for existing integrations, but responses will include the new slug-based ID format. + + .PARAMETER Id + The id of the public photo to update + + .PARAMETER RecordId + Record id to associate with the photo + + .PARAMETER RecordType + Record type to associate with the photo + + .EXAMPLE + Set-HuduPublicPhoto -id 123 -RecordId 1 -RecordType 'asset' + Set-HuduPublicPhoto -id 432 -RecordId 7 -RecordType 'article' + + #> + [CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory)] + [Alias('photo_id')] + [object]$id, + + [Parameter(Mandatory)] + [Alias('record_id')] + [int]$RecordId, + + [Parameter(Mandatory)] + [Alias('record_type')] + [string]$RecordType + ) + $photo = get-hudupublicphotos | Where-Object { $_.numeric_id -eq $id -or $_.id -eq $id } | Select-Object -first 1 + $photo = $photo.public_photo ?? $photo + if (-not $photo) {throw "File not found!"} + if (-not $RecordId) {throw "RecordId is required!"} + if (-not $RecordType) {throw "RecordType is required!"} + + if ($photo.record_id -eq $RecordId -and $photo.record_type -eq $RecordType) { + Write-Verbose "Photo already associated with Record ID $RecordId and Record Type $RecordType. No changes made." + return + } + if ($PSCmdlet.ShouldProcess($File.FullName)) { + Invoke-HuduRequest -Method PUT -Resource "/api/v1/public_photos/$($photo.numeric_id)" ` + -Form @{ + 'record_id' = $RecordId + 'record_type' = $RecordType + } + } +}