Friday, May 2, 2014

Power of Powershell remoting WSMan

If you want to execute powershell script from your local box onto remote server this is the best solution to do.

Before you take deep dive in below powershell script . Ensure few things in local source and destination remote server settings.
* Ensure WinRs windows remote services . Type services.msc and this service should be enabled and auto mode.
* Ensure WSMan is enabled
Use gpedit.msc and look at the following policy:
 
Computer Configuration ->
Administrative Templates ->
System ->
Credentials Delegation -> Allow Delegating Fresh Credentials. 
 
Verify that it is enabled and configured with an SPN appropriate for the target computer.C lick on add server list mention WSMAN/myserver.domain.com
 

set-item wsman:localhost\client\trustedhosts -value *

#Enable credssp authentication
Enable-WSManCredSSP -Role Client –DelegateComputer *

# This will establish server connection
Connect-WSMan myserver

invoke-command -computername myserver-authentication credssp -credential domain\username -filepath c:\dbtest.ps1

  

This will prompt for password and you are good to go.
Now this dbtest.ps1 can be your powershell script which will deploy code base to different environment.

 
Useful References


Write to event log
http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/20/how-to-use-powershell-to-write-to-event-logs.aspx

Monitor Scheduled Job
http://blogs.technet.com/b/heyscriptingguy/archive/2014/04/29/powertip-use-powershell-to-show-state-of-scheduled-tasks.aspx

 
Database administration

No comments :