net session
開いている共有セッションを表示します。
net share
使用可能な共有を表示します。
しかし、特定の共有ごとに開いているセッションのリストを取得するにはどうすればよいでしょうか? GUI で共有、セッション、開いているファイルを一覧表示できることはわかっていますが、GUI はプロセスの自動化には適していません。
答え1
使用する必要があるWin32_ServerConnection クラスこのために。
Powershell では、次のコマンドを使用して共有別にソートされたセッションのリストを取得できます。
Get-WmiObject win32_serverconnection -computername $computername | Select username, computername, sharename | sort sharename
すぐに使える機能:
Function Get-ServerConnection {
Param (
$ComputerName = 'localhost',
$account = '') # if empty, it means all accounts
# Now get the connections from that account
if ($account = '' )
{
Get-WmiObject win32_serverconnection -computername $computername | Select username, computername, sharename | ft -a
}
else
{Get-WmiObject win32_serverconnection -computername $computername | where username -match $account | select username,computername,sharename | sort username
}
}
Get-ServerConnection