New-AzurePSSession.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<#
.Synopsis
    Creates a PSSession with Azure specific configuration.
 
.Description
    Creates a PSSession with Azure specific configuration.
        UseSSL = True
        SessionOption.SkipCACheck = True
        SessionOption.SkipCNCheck = True
 
.Parameter ComputerName
    ComputerName to create a session against.
 
.Parameter Credential
    Credentials to use for the PSSession.
 
#>

function New-AzurePSSession {
    param([parameter(Mandatory)][Alias("Server","DnsName")][string]$ComputerName
        , [parameter(Mandatory)][Alias("VmCred")][pscredential]$Credential
    )

    $splat = @{
        ComputerName = $ComputerName
        Credential = $Credential
        UseSSL = $true
        SessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck
        Name = $ComputerName.split(".")[0]
    }

    New-PSSession @splat
}

Export-ModuleMember -Function New-AzurePSSession