0

Is there a way to use Powershell to clean up/release file locks on a server when it's time to upgrade? we have other systems connecting to the server's shared resources over the network and some files report as locked, which messes up our automated upgrade process

is there any way to run a Powershell script and close all network connections to the server before the upgrade?

thanks!

2 Answers2

0

You can use the command net file in a powershell script to close open files https://support.microsoft.com/en-us/kb/290585

The syntax of this command is:

NET FILE
[id [/CLOSE]]
Mass Nerder
  • 997
  • 4
  • 6
  • thanks for the suggestion! I tried to use this command, with the following format - ` for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close` but despite reporting success, the files remained open... what am I doing wrong? – Oleg Ivanov Apr 28 '16 at 19:17
  • @OlegIvanov Make sure %a is the ID of the open file – Mass Nerder Apr 28 '16 at 19:41
0

You could throw the following line into a Powershell script and run it just before your downtime window begins. This will kill all fileshare sessions.

# The /y ignores the Y/N prompt that normally comes up when removing the sessions.  
# This command will remove ALL sessions.
net session /delete /y
Matt Y
  • 41
  • 4
  • interesting - I tested your suggestion and here is what I found: if a remote session has files open on the server, the command doesn't close the session: it shows all the info, then reports that the command completed successfully, but the sessions stay open (and files, too) thanks for looking into it nonetheless! – Oleg Ivanov Apr 28 '16 at 15:20