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
$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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.