Wednesday, December 26, 2012

Quickie - Enable remote powershell without touching the PC


Quick and convenient way to get WinRM up and running without having to touch the PC.  Useful if you prefer to leave it disabled in your environment unless you need it or have decided to deploy it to a number of existing PCs.  Use scheduled tasks to enable it for you (note: this isn't my trick, so if you're looking for this you probably already saw it elsewhere, just sans commands!)

PS C:\> schtasks.exe /Create /S ComputerName /TR "powershell -ExecutionPolicy Bypass -Command Enable-PSRemoting -Force" /TN EnablePSRemote /SC MONTHLY /RU "SYSTEM"
SUCCESS: The scheduled task "EnablePSRemote" has successfully been created.

PS C:\> schtasks.exe /Run /S ComputerName /I /TN EnablePSRemote
SUCCESS: Attempted to run the scheduled task "EnablePSRemote".

PS C:\> schtasks.exe /Delete /S ComputerName /TN "EnablePSRemote" /F
SUCCESS: The scheduled task "EnablePSRemote" was successfully deleted.

PS C:\> Enter-PSSession -ComputerName ComputerName
[ComputerName]: PS C:\Users\account\Documents>

No comments:

Post a Comment