ONTAP Discussions

Needs Help for CIFS open files in PowerShell

Moh_Kouhi
4,008 Views

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
3,915 Views

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
3,610 Views

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

Public