scriptblock에 함수를 통합하는 방법을 이해하려고 할 때 문제가 있습니다. scriptblock이 필요한 이유는 오케 스트레이터에서 작동하는 사용자 정의 함수를 실행하는 방법을 누군가가 도와 줄 수 없다면 orchestrator에서 powershell 스크립트를 실행하려고하기 때문입니다. 실행하고 싶은 기능 다른 사이트에서 가져 왔지만 변수의 이름을 변경했습니다.Scriptblock에서 함수를 이해할 수 없습니다.
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 {
}
}
를 통해 그것을 호출 할 수 있습니다. –
그는, 음, 당신이 할 필요가있는 유일한 일은, 정의한 후에 함수를 호출하는 것입니다. 따라서 Get-RDPStatus someinput을 호출하십시오. – 4c74356b41
실제로이 함수를 어떻게 추가 할 수 있습니까? 스크립트 블록. 나는 아래의 제안을 prageet으로 사용하려했지만 작동하지 않았다. –