Private/_NewSession.ps1
function _NewSession { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] $Identity ) if (Get-PSSession -Name ADLookups -ErrorAction SilentlyContinue) { Remove-PSSession -Name ADLookups } #region Online Status try { $Script:Session = New-PSSession @SessionSplat -Name ADLookups -ComputerName $Identity -ErrorAction Stop -ErrorVariable ErrorVar if ($Session) { $ADLookups_ComputerTabOnlineEllipse.Fill = '#FF64DD17' $ADLookups_ComputerTabOnlineTextBlock.Text = 'Online' } else { $ADLookups_ComputerTabOnlineEllipse.Fill = '#FFE0E0E0' $ADLookups_ComputerTabOnlineTextBlock.Text = 'Offline' } } catch { # switch ($ErrorVar.FullyQualifiedErrorId) { # 'AccessDenied,PSSessionOpenFailed' { # # Access Denied # Write-Host 'Access Denied.' # } # 'NetworkPathNotFound,PSSessionOpenFailed' { # # Computer not found # Write-Host 'Host not found.' # } # 'URLNotAvailable,PSSessionOpenFailed' { # # Most likely trying to create a session to localhost # Write-Host 'Is this localhost?' # } # Default { # Write-Host 'Unable to create session.' # } # } $ADLookups_ComputerTabOnlineEllipse.Fill = '#FFFF6666' } #endregion } |