Public/Unpublish-UWFFile.ps1
Function Unpublish-UWFFile { <# .SYNOPSIS Deletes the specified file and commits the deletion to the physical volume. .DESCRIPTION Deletes the specified file and commits the deletion to the physical volume. The FileName must contain the name of a file that exists on the physical volume. The CommitFileDeletion method cannot delete a file that does not exist. You must use an administrator account to call this method. .PARAMETER FileName A string that contains the path of the file to delete, but does not include the drive letter or volume name. For example: “\users\test.dat” .INPUTS System.String .OUTPUTS Returns an HRESULT value that indicates WMI status or a WMI error constant. .EXAMPLE Unpublish-UWFFile -FileName "C:\Operator\file.txt" .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Medium" )] Param( [Parameter( Mandatory = $true, HelpMessage = "A string that contains the path of the file to delete, but does not include the drive letter or volume name." )] [string]$FileName ) Begin { If (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } If (-not $PSBoundParameters.ContainsKey('WhatIf')) { $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference') } If (-not $PSBoundParameters.ContainsKey('Confirm')) { $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference') } If (-not $PSBoundParameters.ContainsKey('ErrorAction')) { $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference') } } Process { If ($PSCmdlet.ShouldProcess()) { If (!$Script:UWFVolume) { $ExitCode = 424 Throw "Unable to get handle to an instance of the UWF_Volume class" } $CommitFileDeletion = $Script:UWFVolume.CommitFileDeletion($FileName) $ExitCode = $CommitFileDeletion.ReturnValue } } End { If ($Null -eq $ExitCode) { # 424 Failed Dependency $ExitCode = 424 } If ($ExitCode -eq 0) { Write-Warning "Committing $FileName deletion" } Return $("{0:x0}" -f $ExitCode) } } |