question on copy-item error


i running basic script follows.

netsh interface ip set address "local area connection" static 192.168.0.5 255.255.255.0 192.168.0.1

net use i: \\ftpserver1\cbackups /persistent:yes /user:admin /password:password1

$name = read-host "enter customers email address"

new-item -path "i:\$name" -itemtype directory -force


new-item -path i:\$name\pstfiles -itemtype directory -force 
new-item -path "i:\$name\my documents" -itemtype directory -force
new-item -path "i:\$name\my pictures" -itemtype directory -force
new-item -path "i:\$name\my music" -itemtype directory -force
new-item -path i:\$name\favorites -itemtype directory -force
new-item -path i:\$name\desktop -itemtype directory -force
new-item -path "i:\$name\lync recordings" -itemtype directory -force
new-item -path "i:\$name\my videos" -itemtype directory -force
new-item -path "i:\$name\cdrive" -itemtype directory -force


copy-item "$env:userprofile\documents\*" "i:\$name\my documents" -recurse -force
copy-item "$env:userprofile\pictures\*" "i:\$name\my pictures" -recurse -force
copy-item "$env:userprofile\music\*" "i:\$name\my music" -recurse -force
copy-item "$env:userprofile\favorites\*" i:\$name\favorites -recurse -force
copy-item "$env:userprofile\desktop\*" i:\$name\desktop -recurse -force
copy-item "$env:userprofile\lync recordings\*" "i:\$name\lync recordings" -recurse -force
copy-item "$env:userprofile\videos\*" "i:\$name\my videos" -recurse -force


get-wmiobject -class cim_datafile -filter "drive='c:' , extension='pst'" | 
    % { copy-item $_.name -destination i:\$name\pstfiles -force}

$excludedirs = 'c:\windows','c:\users','c:\program files','c:\program files (x86)','c:\hp' ,'c:\hpexperience','c:\intel','c:\logs','c:\ocsetupdir','c:\perflogs','c:\quarantine','c:\ssm' ,'c:\system.sav','c:\temp'
get-childitem c:\ | where-object {$excludedirs -notcontains  $_.fullname  }  | 
    % { copy-item $_.fullname -destination i:\$name\cdrive -recurse -force}

however getting following error.

copy-item : access path 'c:\users\minnis\documents\my music' denied.
@ line:21 char:10
+ copy-item <<<<  "$env:userprofile\documents\*" "i:\$name\my documents" -recurse -force
    + categoryinfo          : notspecified: (:) [copy-item], unauthorizedaccessexception
    + fullyqualifiederrorid : system.unauthorizedaccessexception,microsoft.powershell.commands.copyitemcommand

but directory c:\users\minnis\documents\my music not exist idea causing , how fix it?



add each copy-item command suppress access errors:

-erroraction silentlycontinue

 alternatively, can change erroractionpreference silentlycontinue before beginning copies, , return old value after copy commands. this:

$lasterroractionpreference = $erroractionpreference $erroractionpreference = 'silentlycontinue'  ### ... copy-item commands go here  $erroractionpreference = $lasterroractionpreference remove-variable lasterroractionpreference



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...