net session
공개 공유 세션을 표시합니다.
net share
사용 가능한 공유를 보여줍니다.
하지만 각 특정 공유에 대해 열려 있는 세션 목록을 어떻게 얻을 수 있습니까? 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