开发者

Get The ServerNames where a User's Session is Disconnected

I wanted to get a script for getting the list of servers fed in through pipeline where a particular user's session is disconnected, i got someting like this, could some one please help me out.

#

#function Get-DisconnectedUsers {

#param(
#[parameter(Mandatory=$true,ValueFromPipeline=$true)]
#[string]$compnames
#)
query session /server:$compnames | where-object{ $_ -notmatch '^ SESSIONNAME' } | foreach-object{ 
$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() 

#$sessions | ?{ $_.State -eq 'Disc' }
#} 
#}



#$ErrorActionPreference = "silentlycontinue"
#Get-VM -VMMServer scvmm01.org |select-object vmhost,ComputerNameString | 
    #Get-DisconnectedUsers -compnames $_.vmhost | Select-Object active,username,state, |
    #Select-Object @{Name='ServerName';Expression={$_.vmhost}},@    #{Name='Username';Expr开发者_C百科ession={$username}},@{Name='State';Expression={$state}}

#| where-Object{$_.user -eq "vinith"}

Could some one please help me to get this modified & working.


Try the PSTerminalServices PowerShell module (http://psterminalservices.codeplex.com/). The following will tell you if the Administrator account has a disconnected session on any of the servers in the file.

Import-Module PSTerminalServices

Get-Content servers.txt | Foreach-Object { 
    Get-TSSession -ComputerName $_ -UserName administrator -State Disconnected
}:
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜