public/Rename-VSADocument.ps1
|
function Rename-VSADocument { <# .Synopsis Renames a document. .DESCRIPTION Rename a single document on the Audit > Documents page. Enter the existing name of the document in the Source parameter and the new name in the Destination parameter. Takes either persistent or non-persistent connection information. .PARAMETER VSAConnection Specifies existing non-persistent VSAConnection. .PARAMETER URISuffix Specifies URI suffix if it differs from the default. .PARAMETER Source Specifies source file name .PARAMETER Destination Specifies destination file name .PARAMETER AgentID Specifies the agent whose document is renamed. .EXAMPLE Rename-VSADocument -AgentId 10001 -Source "OldName.txt" -Destination "NewName.txt" .EXAMPLE Rename-VSADocument -AgentId 10001 -Source "OldName.txt" -Destination "NewName.txt" -VSAConnection $connection .INPUTS Accepts piped non-persistent VSAConnection .OUTPUTS Array of objects that represent Custom Extension Folders and Files. #> [CmdletBinding(SupportsShouldProcess)] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification = 'ShouldProcess is invoked centrally by Invoke-VSAWriteRequest, which receives this cmdlet''s $PSCmdlet via -Caller (module-wide pattern).')] param ( [parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [ValidateNotNull()] [VSAConnection] $VSAConnection, [parameter(DontShow, Mandatory=$false)] [ValidateNotNullOrEmpty()] [string] $URISuffix = 'api/v1.0/assetmgmt/documents/{0}/Rename/{1}/{2}', [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [ValidateScript({ if( $_ -notmatch "^\d+$" ) { throw "Non-numeric Id" } return $true })] [string] $AgentID, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Source, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Destination ) $Source = $Source -replace '\\', '/' $Destination = $Destination -replace '\\', '/' if ($Source -eq $Destination) { [string]$Msg = "The source ($Source) and the destination ($Destination) are the same" throw $Msg } else { # Method confirmed against the official Kaseya REST API docs (Rename Document, # help.vsa9.kaseya.com/help/Content/Modules/rest-api/38166.htm): the documented # operation is genuinely DELETE, not PUT (T-6.9 / F-50). return Invoke-VSAWriteRequest -Method 'DELETE' -URISuffix ($($URISuffix -f $AgentId, (Format-VSAPathSegment $Source), (Format-VSAPathSegment $Destination))) -VSAConnection $VSAConnection -Caller $PSCmdlet } } Export-ModuleMember -Function Rename-VSADocument |