WhatIf parameter

The WhatIf parameter replaces the confirmation prompt with a simple statement that should state what would have been done, using Remove-Item as an example again:

PS> Set-Location $env:TEMP
PS> New-Item IMadeThisUp.txt -Force
PS> Remove-Item .IMadeThisUp.txt -WhatIf

Confirm
Are you sure you want to perform this action?
What If: Performing the operation "Remove File" on target "C:UserswhoamiAppDataLocalTempIMadeThisUp.txt".

If both Confirm and WhatIf are used with a command, WhatIf takes precedence.

WhatIf may be unset on a per-command basis by supplying a value of false in the same manner as the Confirm parameter. Let's look at the following example:

'Some message' | Out-File $env:TEMP	est.txt -WhatIf:$false 

The previous technique can be useful if a file (such as a log file) should be written to, irrespective of whether WhatIf is being used or not.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.40.47