Powershell工作流程/并行Citrix会话

时间:2016-06-16 23:41:33

标签: powershell parallel-processing workflow citrix

编辑 - 我应该通过说我对powershell非常新的来做这个。这是我试图编写的第一个“复杂”脚本之一。

我正在尝试使用workflow / parallel同时针对两个列表运行脚本。在我开始工作之后,我们的目标是添加多个列表,以减少处理每个列表所需的时间。

脚本本身效果很好。添加工作流程什么都不返回:/

$Global:ctxsession = Read-Host -Prompt 'Input the Username'
$serverlist1 = get-content .\serverlist1.txt
$serverlist2 = get-content .\serverlist2.txt
function citrixlist {
#([string]$Servers)
Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$servers
)
foreach ($server in $servers) {
#ping first
if (Test-Connection -count 1 -computer $server -quiet) {
#temporary write-host to see where it hangs (might leave in permanently)
Write-Host $server
#check for sessions
$sessions = qwinsta /server $server| ?{ $_ -notmatch '^ SESSIONNAME' } | %{
    #separating into objects
    $item = "" | Select "Active", "SessionName", "Username", "Id", "State", "Type", "Device"
    $item.Active = $_.Substring(0,1) -match '>'
    $item.SessionName = $_.Substring(1,18).Trim()
    $item.Username = $_.Substring(19,20).Trim()
    $item.Id = $_.Substring(39,9).Trim()
    $item.State = $_.Substring(48,8).Trim()
    $item.Type = $_.Substring(56,12).Trim()
    $item.Device = $_.Substring(68).Trim()
    $item
}

foreach ($session in $sessions){
#match for session name entered
    if ($session.Username -match $ctxsession){
        Write-Host 'Found' $session.Username 'on' $server 'with Session ID' $session.Id $session.State
#Kill session with ID and Server, with verbose switch
    #rwinsta $session.Id /server:$server /v

                }
            }
        }
    }
}

workflow get-citrixlist1 {
citrixlist -servers $serverlist1

}
workflow get-citrixlist2 {
citrixlist -servers $serverlist2

}
workflow get-citrixkill {
parallel {
get-citrixlist1
get-citrixlist2
    }
}

0 个答案:

没有答案