• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

Help moving a file from one server to another server using Powershell

Hello Powershell Experts –

I’m trying to write a powershell script that will check for the existence of a file on the local server (ServerA) and move it to another server (ServerB) if the file exists.  Here is what I have:

$data = Test-Path c:\source\*.cce

if($data = "true"){
$net = New-Object -ComObject wscript.network
$net.MapNetworkDrive("K:", "\\ServerB\target", $false, "MyDomain\file_t", "p@55word")
Move-Item c:\source K:\

When I run the code above, I get a message stating that a drive with the name 'K' does not exist.  When I open Explorer, there is a drive with the drive letter of K.  What am I missing here?  Also, could someone tell me what the $false is.  I put it in the script because all the examples I was basing the code from had it.

Sorry for the dumb questions.

Thanks in advanced for all of your help.

1 Solution
$net = New-Object -comObject WScript.Network
should work if the current user is athenticated
(I perfer not to include passwords in scripts if not required)

Here are the five possible arguments for MapNetworkDrive:

1) strDriveLetter, 2) strRemotePath, 3) bUpdateProfile, 4) strUser, 5) strPassword.
the 'b' stands for Boolean and the allowable values are either ="true" or ="false".

A little more about the third argument, which is referred to as bUpdateProfile.  This optional component controls whether the new mapped network drive should be stored in the user's profile.  Incidentally it took me ages to discover what the 'b' in bUpdateProfile meant, the answer was Boolean, in other words this argument takes either true or false.  The default is false, so the only time you need to enter a value is if you positively want the user to receive this drive every time they logon, in which case you set the bUpdateProfile value to true.

for more details see

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now