Friday, March 21, 2014

CMD for copying a Powershell script locally and running it

CMD / BAT script syntax that can be used to pull a powershell script from a network location, locally and then execute it.

_________________Begin Script______________________
:: Suggested steps
:: - copy the powershell script locally
:: - execute the script from a CMD shell
::
::
::
::COPY STEPS
:: - Define variables for copy
::
SET FILETOCOPY="\\networkserver\servershare\file.txt"
SET DESTINATION="C:\scripts"
SET OPTIONS=/q /y
::
Xcopy %FILETOCOPY% %DESTINATION% %OPTIONS%
::
:: Run Powershell
::
SET SCRIPT="C:\scripts\pws.ps1"
::
powershell.exe -executionpolicy unrestricted -command %SCRIPT%
::
_______________End Script__________________________

No comments:

Post a Comment