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