I'm writing a script to copy files with powershell using mapped drives in file explorer. It has the above error message. This is what it looks like:
function CopyFileToFolderUNC($SourcePath, $DestinationPath){
$temp1 = Get-ChildItem -Path $SourcePath -Recurse -Force #this is the line of error message
Copy-Item -Path $SourcePath -Destination $DestinationPath #source:\* -Destination target #watch out for login boxes when test this
}
#start here
$tempSource = "X:\Credentialing\FORMS"
$ToLocation = "C:\Users\me\Documents\2018\powershellFiles\toLoc"
CopyFileToFolderUNC $tempSource $ToLocation
It has the same error message on the Copy-Item line (if I comment out the Get-ChildItem line) but it fails in Get-ChildItem before that. How do I get it to use the mapped drive on the computer the script is run on? I am running this on a laptop.
I set-executionPolicy RemoteSigned in powershell at the command line.
I have this permission when I run Get-PSSessionConfiguration in powershell at command line:
Permission : NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
I am running as administrator. Powershell prompt is:
[DBG]: PS C:\WINDOWS\system32>>
$PSVersionTable.PSVersion:
Major Minor Build Revision
----- ----- ----- --------
5 1 16299 666
I looked at powershell mapped drive E but they are using a mapped drive on a server so I wasn't sure what I needed that they were doing in the example.
I found this: Net use
So I added
And now it's at least finding the mapped drive.