Codebase list poshc2 / f5144e5a-ce1a-4d37-ab4e-5fec1437c55d/upstream resources / modules / Invoke-WinRMSession.ps1
f5144e5a-ce1a-4d37-ab4e-5fec1437c55d/upstream

Tree @f5144e5a-ce1a-4d37-ab4e-5fec1437c55d/upstream (Download .tar.gz)

Invoke-WinRMSession.ps1 @f5144e5a-ce1a-4d37-ab4e-5fec1437c55d/upstreamraw · history · blame

Function Get-RandomName 
{
    param (
        [int]$Length
    )
    $set    = 'abcdefghijklmnopqrstuvwxyz'.ToCharArray()
    $result = ''
    for ($x = 0; $x -lt $Length; $x++) 
    {$result += $set | Get-Random}
    return $result
}
Function Invoke-WinRMSession {
param (
$username,
$Password,
$IPAddress
)
$PSS = ConvertTo-SecureString $password -AsPlainText -Force
$getcreds = new-object system.management.automation.PSCredential $username,$PSS

$randomvar = (Get-RandomName 5)
New-Variable -Name $randomvar -Scope Global -Value (New-PSSession -ComputerName $IPAddress -Credential $getcreds)
$randomvar = "$"+"$randomvar"
Return "`nSession opened, to run a command do the following:`nInvoke-Command -Session $randomvar -scriptblock {Get-Process} | out-string"

}