I receive the following error when using the New-Item
cmdlet to create backup copies of files:
new-item : Access to the path 'C:\Program Files (x86)\PRTG Network Monitor\webroot\mailtemplates' is denied.
At line:1 char:21
+ foreach ($i in $a) {new-item -itemtype file -name $i.bak}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Program File...t\mailtemplates:String) [New-Item], UnauthorizedAcc
essException
+ FullyQualifiedErrorId : NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand
Here is the command I am executing:
pwd
C:\Program Files (x86)\PRTG Network Monitor\webroot\mailtemplates
$a = ls
foreach ($i in $a) {new-item -itemtype file -name $i.bak}
New-Item
cmdlet to create a test.txt file within that folder Not sure where to go from here.
try this:
foreach ($i in $a) {new-item -itemtype file -name "$($i.basename).bak"}