スクリプトブロックに関数を統合する方法を理解しようとして問題が発生しています。スクリプトブロックが必要な理由は、オーケストレーターでカスタマイズされた機能を実行する方法を誰かが助けてくれなければ、オーケストレーターで PowerShell スクリプトを実行したいからです。実行したい関数を別のサイトから入手しましたが、変数の名前を変更しました。
Function Get-RDPStatus {
param (
[CmdletBinding()]
[string[]]$ComputerName = $env:COMPUTERNAME
)
begin {
$SelectHash = @{
'Property' = @('Name','ADObject','DNSEntry','PingResponse','RDPConnection')
}
}
process {
foreach ($CurrentComputer in $ComputerName) {
# Create new Hash
$HashProps = @{
'Name' = $CurrentComputer
'ADObject' = $false
'DNSEntry' = $false
'RDPConnection' = $false
'PingResponse' = $false
}
# Perform Checks
switch ($true)
{
{([adsisearcher]"samaccountname=$CurrentComputer`$").findone()} {$HashProps.ADObject = $true}
{$(try {[system.net.dns]::gethostentry($CurrentComputer)} catch {})} {$HashProps.DNSEntry = $true}
{$(try {$socket = New-Object Net.Sockets.TcpClient($CurrentComputer, 3389);if ($socket.Connected) {$true};$socket.Close()} catch {})} {$HashProps.RDPConnection = $true}
{Test-Connection -ComputerName $CurrentComputer -Quiet -Count 1} {$HashProps.PingResponse = $true}
Default {}
}
# Output object
New-Object -TypeName 'PSCustomObject' -Property $HashProps | Select-Object @SelectHash
}
}
end {
}
}