Mapping Issue

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
prafulnama
Posts: 3
Last visit: Mon Jan 19, 2009 10:16 am

Mapping Issue

Post by prafulnama »

Hi,I am trying to write a powershell script to move files across domains. In order to do that, I need to pass credentials that will enable me to access the remote server. Since the 'move-item' cmdlet only allows me to pass the username, I am trying to map the remote drive and then copy the files to it.While doing this, I am experiencing some weird behavior. I am able to map the drive successfully using -$net = New-Object -com WScript.Network$net.mapnetworkdrive($drive, $path, "true",$username,$password)I can also disconect the drive using - $net.RemoveNetworkDrive($drive,"true","true")I have the following problems:1. If I try to 'test-path $drive' after mapping it, it returns 'false', though I can see it and access it through Windows Explorer. I am not able to figure out why. I have a couple of other drives that are mapped by my logon script and a test-path on them returns 'true'.2. After mapping the drive, if I try copying an item to it using - move-item -path 'c:file.log' -destination $drive - it returns the following error - Cannot find drive. A drive with name $drive does not exist.If I try to manually copy the files, it works.If someone could please shed some light on what is happening, I'll really appreciate it.Thanks,-p
User avatar
prafulnama
Posts: 3
Last visit: Mon Jan 19, 2009 10:16 am

Mapping Issue

Post by prafulnama »

Hi,I am trying to write a powershell script to move files across domains. In order to do that, I need to pass credentials that will enable me to access the remote server. Since the 'move-item' cmdlet only allows me to pass the username, I am trying to map the remote drive and then copy the files to it.While doing this, I am experiencing some weird behavior. I am able to map the drive successfully using -$net = New-Object -com WScript.Network$net.mapnetworkdrive($drive, $path, "true",$username,$password)I can also disconect the drive using - $net.RemoveNetworkDrive($drive,"true","true")I have the following problems:1. If I try to 'test-path $drive' after mapping it, it returns 'false', though I can see it and access it through Windows Explorer. I am not able to figure out why. I have a couple of other drives that are mapped by my logon script and a test-path on them returns 'true'.2. After mapping the drive, if I try copying an item to it using - move-item -path 'c:file.log' -destination $drive - it returns the following error - Cannot find drive. A drive with name $drive does not exist.If I try to manually copy the files, it works.If someone could please shed some light on what is happening, I'll really appreciate it.Thanks,-p
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Mapping Issue

Post by jhicks »

The easiest solution is to the use the class NET USE command

net use X: file02data /user:mydomainadmin P@ssw0rd
User avatar
prafulnama
Posts: 3
Last visit: Mon Jan 19, 2009 10:16 am

Mapping Issue

Post by prafulnama »

Hi,Thanks. The net use maps the drive but the problems persist. test-path to the mapped drive returns false and the move-item returns the exact same error. The strange part is that I can access the drive using explorer but not powershell. Could this by any chance be because of a problem on my local system?
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Mapping Issue

Post by jhicks »

Test-Path should work, especially if you can see the drives in Explorer. Post the commands you are using to map and test the drive.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Mapping Issue

Post by jhicks »

Using NET USE to map a drive and then copy-item from that drive works just fine for me. The error message you have refers to Set-Location which is a little odd. You weren't in the X: drive when you tried to run this code were you?

The other thing I can think to try is use Test-path again to verify the NET USE command worked.

If ((Test-path "x:") -AND (Test-path "y:")) {
copy-item X:* -destination Y: -force
}
else {
write-warning "A network drive is missing"
}
This topic is 15 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked