【发布时间】:2017-05-25 03:26:36
【问题描述】:
我在尝试了解如何在脚本块上集成功能时遇到问题。我需要脚本块的原因是因为我想在 Orchestrator 中运行一个 powershell 脚本,除非有人可以帮助我如何在 Orchestrator 中运行一个有效的自定义函数。我想运行的函数是从另一个站点获得的,但我更改了变量的名称。
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 -
实际上问题是我如何添加这个函数来处理脚本块。我尝试使用 prageet 下面的建议,但没有奏效。
标签: function powershell orchestration scriptblock