Public/Enable-Remoting.ps1

function Enable-Remoting {
    <#
    .Synopsis
    -Taylor Lee
    Modified 05172019
 
    .Description
    This Command will enable PowerShell Remoting on a remote PC.
 
    .NOTES
    This function requires psexec. If you do not, download it with the sysinternals suite. Add psexec to one of your enviroment variable paths.
 
    .EXAMPLE
    This will enable remoting and then prompt for credentials
 
    Enable-PSRemoting -computer PCName -username domain\username
    #>


    [CmdletBinding()]

    Param (
        [Parameter(Position = 0, Mandatory = $true)]$Computer,
        [Parameter(Position = 1, Mandatory = $false)]$Username,
        [Parameter(Position = 2, Mandatory = $false)][SecureString]$Password
    )

    #Enabling PSRemoting
    PsExec.exe \\$Computer -s winrm.cmd quickconfig -q
    PsExec.exe \\$Computer -u $Username -p $Password powershell.exe cmd /c "enable-psremoting -force"


    #Testing that PSRemoting is now enabled.
    Write-Host "If an error is presented after this point PSRemoting wasn't enabled"       -Foregroundcolor Yellow
    Test-WSMan $Computer
}