ps/Modules/Alkami.PowerShell.Common/Public/Test-ComputerIsAvailable.ps1

29 lines
723 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Test-ComputerIsAvailable {
<#
.SYNOPSIS
Test that a given computer is on and able to be connected to
.PARAMETER ComputerName
[string] Computer to connect to. Assumes .fh.local domain
.PARAMETER NotFHLocal
[switch] Disable check to see if it is a .fh.local computer name
#>
[CmdletBinding()]
[OutputType([bool])]
param (
[string]$ComputerName,
[switch]$NotFHLocal
)
try {
if (!$NotFHLocal -and !$ComputerName.EndsWith('.fh.local')) {
$ComputerName = "$ComputerName.fh.local"
}
$session = New-PSSession -ComputerName $ComputerName
Remove-PSSession $session
return $true
} catch {
return $false
}
}