ONTAP Discussions

Needs Help for CIFS open files in PowerShell

Moh_Kouhi

Hello Everyone, 

I am trying to create a script file to get a list of CIFS open file through the PowerShell tool and the main reason of creating this script is our helpdesk team wants to see who left a file open and ask him to close it. We don't wanna use the MMC feature since it provides some unwanted access for helpdesk team. 

I am using the following context and it's working but it generates an output of all SVMs and I wanna be more specific . So, I like to provide an ability for helpdesk team to input a desire SVM name or  Windows User or path. this file will be exported to a csv file to facilitate searching purpose.

Connect-NcController "Controller Name"
Add-NcCredential
Get-NcCifsSessionFile | %{
$session = Get-NcCifsSession -SessionId $_.SessionId

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

$data
}  | Export-Csv -Path "c:\cifs.csv"  -UseCulture -NoTypeInformation

 

2 REPLIES 2

donny_lang

For filtering by a specific SVM, you could use Read-Host to accept input from the person running the script, store it as a variable, and then use the variable in the -Vserver parameter of the Get-NcCifsSessionFile cmdlet. 


For user/path, there isn't a cmdlet parameter that will accept those values, but you could collect the data using Get-NcCifsSession like you have in your code now, and then filter by user/path by piping Get-NcCifsSession to Where-Object to only show relevant data. 

BayernMunich

Hi Donny_Lang,

 

Unfortunately, we're only getting back a shorted output of the open files using Get-NcCifsSession - over the last run there were just about 4 thousand out of a total of 57 thousand.

Do you have (or anyone has) any idea what could be the reason for this and how we might get the problem solved?

 

Thanks and regards
Andreas

Announcements
Register for Insight 2021 Digital

INSIGHT 2021 Digital: Meet the Specialists 2

On October 20-22, gear up for a fully digital, totally immersive virtual experience with a downright legendary lineup of world-renowned specialists. Tune in for visionary conversations, solution deep dives, technical sessions and more.

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