0

I'm trying to create script that will connect to remote server (Windows server 2012 with PS4.0), and extract 5 different files from one directory to another on the remote server. The script is using psexec.exe to run commands remotely.

psexec \\$server -u <username> -p <password> powershell start Expand-Archive -path "zipfilepath" -destinationpath "destpath"

The expected result is to extract 5 ZIP files inside directory to another directory on remote server.

Dor Shamay
  • 345
  • 1
  • 4
  • 21
  • Hello and welcome to SO. SO is a community of developers helping developers. A developer can range from just learning to being a expert. So if you are wanting to learn how to code then I would suggest that you try making this script yourself and then ask question around the things you are struggling to learn. Show code that you have made and ask direct questions about the issue with the code. If you are looking for someone to just write a script for you that is why you hire a developer. It seems you have a script you made. If you post it and what the issue is the community could help. – ArcSet Jun 04 '19 at 19:55
  • Thanks for your comment, I'll edit the post. – Dor Shamay Jun 04 '19 at 19:56
  • Great fix. So are you running this script in powershell? – ArcSet Jun 04 '19 at 20:00
  • Yes, I'm running this script in remote PowerShell, on ps4.0. to avoid long comments I'd like to chat with you if it possible. – Dor Shamay Jun 04 '19 at 20:09

1 Answers1

0

OK so what you can do is use a Script Block {} and seperate the commands with ;

Powershell -command {Command1;Command2;Command3;etc...}

so something like :

psexec \\$server -u <username> -p <password> powershell -command { Expand-Archive -path "zipfilepath" -destinationpath "destpath"; Expand-Archive -path "zipfilepath" -destinationpath "destpath"; Expand-Archive -path "zipfilepath" -destinationpath "destpath"}
ArcSet
  • 6,518
  • 1
  • 20
  • 34
  • Can I use ```ExtractToDirectory``` module and not Expand-Archive? this way with **Script Block** ```{}``` ? – Dor Shamay Jun 04 '19 at 20:20