Forum Discussion
copy-item-move-item or remove-item server\fileshare access denied
I am trying a lot of things to get the following working:
We have a fileshares of which the structure is like:
\\server\$nameshare (for example: \\test\username where username is a folder)
Regurlarly we must delete these fileshares so i would like to do this with powershell. Accually there are 2 of those shares but if above is succeeding i will try that with another share.
The problem is i have tried to copy the sharefolder with all of its contents to another networkshare and then remove-item the original foldershare. Then getting a access denied.
Tried to move-item the folder, access denied
THen tried to delete the folder with cmd in powershell but cmd is not accepting the variable $name for the foldersharename which i start the script with.
I have started Powershell as an admin so have enough rights, ik also came accross the fact that many people have this and must first take ownership of the folder?
param ($naam)
if ($naam -eq $null){
$naam = Read-Host -Prompt "Please enter user logon name"
}
get-aduser $name
Set-ADUser $name .........
Copy-Item \\server\$name \\server\sharename\username\ -Recurse -force
#cmd /c 'rd /s /q \\server\$naam' (this one does not accept $name
Also tried it without -force. And tried first the deletion of all files but keep geting access denied.
Is it possible to do first a enter-pssession to the server and then get-childitem | remote-item? but to automate the pssession automaticcaly fill in the server\sharename like i also fill in the username or something like that
- farismalaebSteel Contributor
if you try Set-Location \\ShareServer\Username are you able to access the folder via this command
this seems to be a permission issue and ownership