CamFlyerCH / FileShareUtils

Powershell module to help with all file server tasks without using WMI
MIT License
12 stars 3 forks source link

[Feature RequestPossibility to close a file listed in Get-NetOpenFiles #7

Closed n3rdopolis closed 4 years ago

n3rdopolis commented 4 years ago

Hi

One feature that would be cool is the ability to close files. Not sure how possible it would be, but it would be nice to filter out file matches, and then pipe them in, to close them...

Currently it's possible to verify if a user has a file open, but to close it, you'll still need to use compmgmt.msc, and sift through the list

Thanks

CamFlyerCH commented 4 years ago

I like to implement this soon and also a close session command. Found a good starting point here : https://stackoverflow.com/questions/40458957/force-close-an-open-network-file-on-windows-server-2012-with-c-sharp

CamFlyerCH commented 4 years ago

I added two new functions to close files and sessions and I also needed the option to output the FileID with Get-NetOpenFiles in order to use Close-NetOpenFiles. @n3rdopolis Can you please get the latest Version here and test is before I publish this version to the PowerShell Gallery ?

n3rdopolis commented 4 years ago

Thanks! I tried it, It mostly works, but there is a problem with Get-NetOpenFiles, and the problem is that it seems that on a server that has been up for a while, you get file ID's higher than 2147483647 (higher than an 32 bit signed integer), and it fails
Changing the argument to NetFileClose to unsigned seems to work.

Close-NetSession works great, but I think an error message could be tweaked if possible. If you kill the session that is being used to list the sessions with compmgmt.msc, you get an error that states "you can't terminate the session that is being used to administer the server", where Close-NetSession just shows a generic "remote procedure call failed" error.

CamFlyerCH commented 4 years ago

I changed the variable type to unit / uint32 and tested it on a filer with such high numbers with success. Regarding the errors I do no processing and transfer the API errors directly. I don't plan to implement any fancy logic to detect this "user error". I released and published version 1.0.22 that solves this issue.