October 2017
Intermediate to advanced
440 pages
11h 47m
English
The Force parameter has a different purpose.
With the Force parameter, New-Item will overwrite any existing file with the same path. When used with Remove-Item, the Force parameter allows removal of files with Hidden or System attributes. The error generated when attempting to delete a Hidden file is shown in the following code:
PS> Set-Location $env:TEMPNew-Item IMadeThisUp.txt -ForceSet-ItemProperty .\IMadeThisUp.txt –Name Attributes –Value HiddenRemove-Item IMadeThisUp.txtRemove-Item : Cannot remove item C:\Users\whoami\AppData\Local\Temp\IMadeThisUp.txt: You do not have sufficient access rights to perform this operation.At line:1 char:1+ Remove-Item .\IMadeThisUp.txt+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: ...
Read now
Unlock full access