Hi everybody, I'm new here (and in Powershell) and probably this question was asked many times. I just couldn't catch whats wrong with my code (it's simple code to copy folders tree to new tree like year/moth/day/copied_tree). So here is it:
$path = Get-ChildItem c:\zPS\test\ztest -Recurse | ?{$_.PsIsContainer -eq $true} $Year = Get-Date -uFormat "%Y" $Month = Get-Date -uFormat "%m" $Day = Get-Date -uFormat "%d" $dest = $z $zpath = 'C:\zPS\test\ztest1\' $parent = $path[0].Parent.Name $path | foreach { $z = New-Item -Path $zpath\"$Year"\"$Month"\"$Day" -Type "directory" -ErrorAction SilentlyContinue $_.FullName -match "$parent.+" New-Item -ItemType directory ($dest + $Matches[0]) #-ErrorAction SilentlyContinue }
After I run it, I get following:
New-Item : Access to the path 'test' is denied.
At line:11 char:9
+ New-Item <<<< -ItemType directory ($dest + $Matches[0]) #-ErrorAction SilentlyContinue
+ CategoryInfo : PermissionDenied: (C:\Program File...2008\ztest\test:String) [New-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand
So hope for you help. Tnx in advance.