You don't have to pipe anything. Put this in the script block (change the share name, of course!):
$ShareName = "Junk"
$p = (Get-SmbShare $ShareName).Path
Remove-SmbShare $ShareName -Force
Remove-Item -Path $p
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We have shared folders which must be copied and deleted regurally. So i made a powershell script and try to do copy and delete the share but i can only copy the complete folderstructure but not delete it and not move it remotely. When all subfolders and files are copied to another server then the rootfolder share is empty but cannot be deleted remotely not in a batchfile with cmd not with powershell and not with robocopy. Process is in use. But when i make a new share end trie it is also not deleted, just the subfolders. When i delete the complete patch remotely then it can be deleted but not the share. \servername\share what can be deleted is: \servername\patch to share\share or \servername\e$\patch Is there somewhere a setting that prevents deleting rootfolder shared folders?
You don't have to pipe anything. Put this in the script block (change the share name, of course!):
$ShareName = "Junk"
$p = (Get-SmbShare $ShareName).Path
Remove-SmbShare $ShareName -Force
Remove-Item -Path $p
I have tried above script but this is not asking for the sharename so it gives an error.
Filled in the destination in
$t = (Get-SmbShare $Using:firstpath).Path
$t += "\server\pathtodestination\Users\$Using:naam\"
and in the second:
$t = (Get-SmbShare $Using:secondpath).Path
$t += "\server\pathtootherdestination\$Using:naam\"
Gives the following:
No MSFT_SMBShare objects found with property 'Name' equal to ''. Verify the value of the property and retry
etc etc
I have now tried this agin but then in 2 steps: 1. the first share and then again the second share. Strange for me is that the first time with the first share copy-item works and the share is deleted, but when i want to start the second script, again asking for the name copy-item does not start, but the removing the share and folder is working so then i have no copy...
This is to risky to execute because it is deleting but not copying the second share.
Is it not possible to ask 2 times for the name and give the second input a different name or something?