Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created February 20, 2012 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Iristyle/1870431 to your computer and use it in GitHub Desktop.
Save Iristyle/1870431 to your computer and use it in GitHub Desktop.
WinRM alias for Microsoft.Powershell_Profile.ps1 to hide the ugliness that is starting a remote session
function Start-RemoteSession
{
param(
[parameter(Mandatory=$true)]
[string] $HostName,
[parameter(Mandatory=$true)]
[string] $UserName,
[parameter(Mandatory=$true)]
[string] $Password
)
$params = @{
ComputerName = $HostName;
Credential = New-Object System.Management.Automation.PsCredential($UserName,(ConvertTo-SecureString $Password -AsPlainText -force))
}
Enter-PSSession @params
}
@Iristyle
Copy link
Author

Add to your Powershell profile - typically stored in %userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Use in a session like:
Start-RemoteSession 'server' 'user' 'password'

Way easier than the wacky credential / secure string shenanigans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment