Closed
Description
The "Correct" version of this isn't quite right.
function Set-File
{
[CmdletBinding(SupportsShouldProcess=$true)]
Param
(
# Path to file
[Parameter(Mandatory=$true)]
$Path,
[Parameter(Mandatory=$true)]
[string]$Content
)
if ($PSCmdlet.ShouldProcess($Path, ("Setting content to '{0}'" -f $Content)))
{
$Content | Out-File -FilePath $Path
}
else
{
# Code that should be processed if doing a WhatIf operation
# Must NOT change anything outside of the function / script
}
}
Update reference documentation to include this one:
https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: ec5ae6fd-4f1f-7a93-db49-237864454bcc
- Version Independent ID: 5db4489e-ffb8-7432-416e-3902cc42c2ba
- Content: ShouldProcess - PowerShell
- Content Source: reference/docs-conceptual/PSScriptAnalyzer/Rules/ShouldProcess.md
- Product: powershell
- Technology: powershell-conceptual
- GitHub Login: @sdwheeler
- Microsoft Alias: sewhee