Выбрать главу

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 \PIPE\spools, 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 CPANDL\williams
601295425045 601295421577 C: \Windows\SYSVOL cpan… 10.0.0.60 CPANDL\CORPPC29$
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.

Stopping file and folder sharing

To stop sharing a folder, follow these steps:

1. Do one of the following:

In Server Manager, select the share you want to manage on the Shares subnode of the File And Storage Services node.

In Computer Management, connect to the computer on which you created the share, and then access the Shares node.

2. Press and hold or right-click the share you want to remove, tap or click Stop Sharing, and then tap or click Yes to confirm the action.

CAUTION You should never delete a folder containing shares without first stopping the shares. If you fail to stop the shares, Windows Server 2012 R2 attempts to reestablish the shares the next time the computer is started, and the resulting error is logged in the system event log.