Пример на PowerShell
Код:
do {
Write-Host "-----------------------------"
Write-Host "Выберите пункт меню:"
Write-Host "1. Завершение сессий пользователей на server01" -ForegroundColor Yellow
Write-Host "2. Завершение сессий пользователей на server02" -ForegroundColor Yellow
Write-Host "3. Завершение сессий пользователей на server03" -ForegroundColor Yellow
Write-Host "4. Завершение сессий пользователей на server04" -ForegroundColor Yellow
Write-Host "5. Завершение сессий пользователей на server-term" -ForegroundColor Yellow
Write-Host "6. Завершение сессий пользователей на server-term-01" -ForegroundColor Yellow
Write-Host "7. Завершение сессий пользователей на всех RDS" -ForegroundColor Yellow
Write-Host "8. Exit" -ForegroundColor Yellow
Write-Host
$choice = Read-Host "Введите номер"
Switch($choice){
1{
$srv = "server01"
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
Write-Host "Завершенные сессии на $srv :" -ForegroundColor Yellow
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
$user
}
}
Write-Host "Выполнено" -ForegroundColor Yellow
}
2{
$srv = "server02"
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
Write-Host "Завершенные сессии на $srv :" -ForegroundColor Yellow
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
$user
}
}
Write-Host "Выполнено" -ForegroundColor Yellow
}
3{
$srv = "server03"
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
Write-Host "Завершенные сессии на $srv :" -ForegroundColor Yellow
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
$user
}
}
Write-Host "Выполнено" -ForegroundColor Yellow
}
4{
$srv = "server04"
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
Write-Host "Завершенные сессии на $srv :" -ForegroundColor Yellow
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
$user
}
}
Write-Host "Выполнено" -ForegroundColor Yellow
}
5{
$srv = "server-term"
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
Write-Host "Завершенные сессии на $srv :" -ForegroundColor Yellow
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
$user
}
}
Write-Host "Выполнено" -ForegroundColor Yellow
}
6{
$srv = "server-term-01"
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
Write-Host "Завершенные сессии на $srv :" -ForegroundColor Yellow
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
$user
}
}
Write-Host "Выполнено" -ForegroundColor Yellow
}
7{
$srvrs = "server01","server02","server03","server04","server-term","server-term-01"
foreach ($srv in $srvrs){
$sessions = Get-TSSession -ComputerName $srv
$users = $sessions.username
foreach($user in $users){
if($user -ne ""){
Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force
}
}
}
}
8{
Write-Host "Выход"; exit
}
default {Write-Host "Такого пункта нет" -ForegroundColor Red}
}
} until ($choice -eq '8')
то есть, строка должна быть такой
Код:
PowerShell -Command "& {$srvrs = 'server01','server02','server03','server04','server-term','server-term-01'; foreach ($srv in $srvrs){$sessions = Get-TSSession -ComputerName $srv; $users = $sessions.username; foreach($user in $users){if($user -ne ''){Get-TSSession -ComputerName $srv -UserName $user | Stop-TSSession -Force}}}}"