Книга: Windows Server 2012 R2 Storage, Security, & Networking Pocket Consultant

Viewing user and computer sessions

Viewing user and computer sessions

You can use Computer Management to track all connections to shared resources on a Windows Server 2012 R2 system. Whenever a user or computer connects to a shared resource, Windows Server 2012 R2 lists a connection in the Sessions node.

To view connections to shared resources, enter net session at an elevated command prompt or Get-SMBSession at an elevated Windows PowerShell prompt. You also can follow these steps:

1. In Computer Management, connect to the computer on which you created the shared resource.

2. In the console tree, expand System Tools, expand Shared Folders, and then select Sessions. You can now view connections to shares for users and computers.

The columns for the Sessions node provide the following important information about user and computer connections:

? User The names of users or computers connected to shared resources. Computer names are shown with a $ suffix to differentiate them from users.

? Computer The name of the computer being used.

? Type The type of network connection being used.

? # Open Files The number of files with which the user is actively working. For more detailed information, access the Open Files node.

? Connected Time The time that has elapsed since the connection was established.

? Idle Time The time that has elapsed since the connection was last used.

? Guest Whether the user is logged on as a guest.

As shown in the following example, the output of Get-SMBSession provides the session ID, client computer name, client user name and the number of open files for each session:

SessionId ClientComputerName ClientUserName NumOpens
601295421497 10.0.0.60 CPANDLwilliams 2

Managing sessions and shares

Managing sessions and shares is a common administrative task. Before you shut down a server or an application running on a server, you might want to disconnect users from shared resources. You might also need to disconnect users when you plan to change access permissions or delete a share entirely. Another reason to disconnect users is to break locks on files. You disconnect users from shared resources by ending the related user sessions.

ENDING INDIVIDUAL SESSIONS

To disconnect individual users from shared resources, enter net session computername /delete at an elevated command prompt or Close-SMBSession at -Computer Name computername an elevated Windows PowerShell prompt. In both instances, computername is the DNS name or IP address of computer from which the session originates.

You also can disconnect users by following these steps:

1. In Computer Management, connect to the computer on which you created the share.

2. In the console tree, expand System Tools, expand Shared Folders, and then select Sessions.

3. Press and hold or right-click the user sessions you want to end, and then tap or click Close Session.

4. Tap or click Yes to confirm the action.

ENDING ALL SESSIONS

To disconnect all users from shared resources, follow these steps:

1. In Computer Management, connect to the computer on which you created the share.

2. In the console tree, expand System Tools, expand Shared Folders, and then press and hold or right-click Sessions.

3. Tap or click Disconnect All Sessions, and then tap or click Yes to confirm the action.

NOTE Keep in mind that you’re disconnecting users from shared resources, not from the domain. You can use only logon hours and Group Policy to force users to log off after they’ve logged on to the domain. Thus, disconnecting users doesn’t log them off the network. It just disconnects them from the shared resource.

To disconnect individual users from shared resources, enter net session computername /delete at an elevated command prompt or Close-SMBSession at -ComputerName computername an elevated Windows PowerShell prompt. In both instances, computername is the DNS name or IP address of computer from which the session originates.

You also can use Windows PowerShell to disconnect all users from a shared resource. The key here is to ensure you only close the sessions you want to close. Consider the following example:

ForEach-Object ($Session in (Get-SMBSession)) {Close-SMBSession -force}

This example uses a ForEach loop to get all active SMB sessions and then close each SMB session in turn. Thus, if you enter this example at an elevated Windows PowerShell prompt, you will disconnect all users from all shared resources.

To close all connections only for a specific share, you must create a ForEach loop that only examines the connections for that share, such as:

ForEach-Object ($Session in (Get-SMBShare CorpData | Get-SMBSession)) {Close-SMBSession -force}

This example uses a ForEach loop to get all active SMB sessions for the CorpData share and then close each of those sessions in turn. Thus, if you enter this example at an elevated Windows PowerShell prompt, you only disconnect users from the CorpData share.

Managing open resources

Any time users connect to shares, the individual file and object resources they are working with are displayed in the Open Files node. The Open Files node might show the files the user has open but isn’t currently editing.

You can access the Open Files node by following these steps:

1. In Computer Management, connect to the computer on which you created the share.

2. In the console tree, expand System Tools, expand Shared Folders, and then select Open Files. This displays the Open Files node, which provides the following information about resource usage:

? Open File The file or folder path to the open file on the local system. The path might also be a named pipe, such as PIPEspools, which is used for printer spooling.

? Accessed By The name of the user accessing the file.

? Type The type of network connection being used.

? # Locks The number of locks on the resource.

? Open Mode The access mode used when the resource was opened, such as read, write, or write+read.

You also can use Get-SMBOpenFile to list open files. As shown in the following example, Get-SMBOpenFile provides the file ID, session ID, path, share relative path, client computer name, and client user name for each open file:

FileId SessionId Path ShareRelativePath ClientComputerName ClientUserName
601295424973 601295421497 C: PrimaryData 10.0.0.60 CPANDLwilliams
601295425045 601295421577 C: WindowsSYSVOL cpan… 10.0.0.60 CPANDLCORPPC29$

CLOSING AN OPEN FILE

To close an open file on a computer’s shares, follow these steps:

1. In Computer Management, connect to the computer with which you want to work.

2. In the console tree, expand System Tools, expand Shared Folders, and then select Open Files.

3. Press and hold or right-click the open file you want to close, and then tap or click Close Open File.

4. Tap or click Yes to confirm the action.

You also can use Close-SMBOpenFile to close open files. When you close a file, you use the -FileID parameter to specify the identifier for the file to close, such as:

Close-SMBOpenFile -FileID 601295424973

Add the -Force parameter to force close the file if needed. However, if the file has been modified by a user, any changes to the file could be lost.

CLOSING ALL OPEN FILES

To close all open files on a computer’s shares, follow these steps:

1. In Computer Management, connect to the computer on which the share is created.

2. In the console tree, expand System Tools, expand Shared Folders, and then press and hold or right-click Open Files.

3. Tap or click Disconnect All Open Files, and then tap or click Yes to confirm the action.

You also can use Windows PowerShell to close all open files on a computer’s share. The key here is to ensure that you only close the files you want to close. Consider the following example:

ForEach-Object ($Session in (Get-SMBOpenFile)) {Close-SMBOpenFile -force}

This example uses a ForEach loop to get all open SMB files, and then close each SMB file in turn. Thus, if you enter this example at an elevated Windows PowerShell prompt, you will close all open files for all shared resources.

To close open files on a specific share, you must create a ForEach loop that only examines the open files for that share, such as:

ForEach-Object ($Session in (Get-SMBShare CorpData | Get-SMBOpenFile)) {Close-SMBOpenFile -force}

This example uses a ForEach loop to get all open SMB files for the CorpData share and then close each of those files in turn. Thus, if you enter this example at an elevated Windows PowerShell prompt, you only close open files for the CorpData share.

Оглавление книги


Генерация: 1.347. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз