Enable PS-remoting on remote servers


Folks,

I had to enable ps-remoting on multiple Windows 2008 R2 servers recently, I used PSexec to enable this remotely since I was clueless on the options and found no articles found else where.

Input computers in Servers.txt

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# This portion will convert your passwor to plain text
function ConvertFrom-SecureToPlain {
param( [Parameter(Mandatory=$true)][System.Security.SecureString] $SecurePassword)
# Create a “password pointer”
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
# Get the plain text version of the password
$PlainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
# Free the pointer
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
# Return the plain text password
$PlainTextPassword
}

$date = get-date
$fileContent = @()
$list = Get-Content .\Servers.txt
function get-account()

foreach ($computer in $list)
{

if ($daaccount -eq $Null)
{
$account= Read-host “Enter your domain admin account”
$daaccount=”Domain\”+$account
$password = Read-host “Enter your domain admin password” -AsSecureString
$passwordplain = ConvertFrom-SecureToPlain $password
}

# this will enable remote powershell on servers
.\psexec \\$computer -h -u $daaccount -p $passwordplain cmd /c ‘echo . | powershell.exe -command “enable-psremoting -force” ‘

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This might be not a  secure way of doing it, if you are much worried about the password security please review script before doing, nothing to worry it just take your password in plan text for running psexec and clears it after execution.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s