Microsoft Virtualization Discussions

Need help with Powershell commands for CIFS Sessions

MAHESH1111111

I was trying to script to list all the open CIFS connections along with the Complete File path that is open to identify the share the user is connected to, then I could filter the share I’m interested in and disconnect all the sessions related to that share.

 

I couldn’t find a Get command that can give this information, For Ex:

 

4.jpg

 

  • Get-NcCifsSessionFile – gives the file name but not the entire path.
  • Get-NcCifsSession – gives the ConnectionId but not the path.

 

I remember you mentioned about doing this completely using Powershell, would you be able to help identify the commands for below:

 

  • Get the list of Files (along with their Share Paths) that have an ongoing session along with Connection ID.
  • Use the Connection ID to kill the session of the user.

 

Thanks for your help in advance.

2 REPLIES 2

asulliva

Hello @MAHESH1111111,

 

The share name is a property of the object returned by Get-NcCifsSessionFile.  You can see the full path using this snippet:

 

Get-NcCifsSessionFile | Select SessionId,Vserver,Share,Path

If you want a bit more thorough output, you could do something like this:

 

Get-NcCifsSessionFile | %{
    $session = Get-NcCifsSession -SessionId $_.SessionId

    $data = "" | Select "WindowsUser", "SVM", "Path"
    
    $data.WindowsUser = $session.WindowsUser
    $data.SVM = $_.Vserver
    $data.Path = "\\$($session.LifAddress)\$($_.Share)\$($_.Path)"

    $data
}

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

MAHESH1111111

Thanks so much Andrew - updated your command to come up with below:

 

Get-NcCifsSessionFile | Select SessionId,Vserver,Share,Path,ConnectionId,HostingVolume,Node | Select-String -Pattern <ShareName> | Get-Unique

 

Close-NcCifsSession -ConnectionId <ConnectionId> -Node <Node> -VserverContext <DataVserver> -Confirm:$false -SessionId <SessionId>

 

Above two commands will give the list of open files and sessions for a particular share and the details we get from that command can then be scripted to dosconnect the same session.

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public