Link to home
Start Free TrialLog in
Avatar of Nana Hemaa
Nana HemaaFlag for United States of America

asked on

Poweshell file to remote server

I am looking into a PowerShell script to achieve this

Copy a file from a local server path:   c:\PurchaseInfo\PurchaseDetails.txt   to a remote server  \\22.22.22.22\CustomerFolder
I have to log into the  remote server  \\22.22.22.22\CustomerFolder   before  I can copy the file each time.  I want to embed the login credentials in a script to copy the file daily @ 10.00PM to the remote server.   The username for the server is  "Testuser" and password is 'TestPassword"


.  Thx
Avatar of Qlemo
Qlemo
Flag of Germany image

We can use plain old batch (.cmd) commands. No pro in using PS here:
net use \\22.22.22.22 /u:Testuser TestPassword
copy c:\PurchaseInfo\PurchaseDetails.txt \\22.22.22.22\CustomerFolder\
net use \\22.22.22.22 /d 2>nul >nul

Open in new window

The same code works in PowerShell.
Avatar of Nana Hemaa

ASKER

ok thanks.  What  can I use to schedule this to run on daily basis?
SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
^^ Exactly what he said
Qlemo.
Thx.. if the file is already there,  I want to rename it  to PurchaseDetails10192016.txt before I write the new file  PurchaseDetails.txt again
You meant to rename with the current date?
yes
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks one last thing.. after I copy  the file I want to delete this file PurchaseDetails.txt  from   c:\PurchaseInfo\PurchaseDetails.txt
I wouldn't do that. Move the file instead - replace copy by move, and it is an atomic operation removing the file only if it has been copied successfully over.
Thanks.  That makes more sense