Whenever you are executing code that can perform a destructive operation, it makes sense to implement the ShouldProcess method introduced with PowerShell v2 advanced functions. Implementing ShouldProcess in an advanced function gives you the ability to add the common risk mitigation parameters such as -Whatif and -Confirm. The following function takes our previous code up a notch, written as an advanced function that implements ShouldProcess. Add the following function to your Exchange Management Shell session:
function RemovemailboxItem { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "High" )] param( [Parameter( Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true )] [String] $PrimarySmtpAddress, ...