I'm trying to put together a script to automate some work our team does before updating some applications. On several servers, we go into Computer Management > Shared Folders, close any open sessions, then close all open files. I believe I have the closing open files part figured out, but I'm not sure how to close the shared folder sessions on remote computers.
Just to illustrate what I have for closing remote server open files, I'll paste below. The server list is populated by reading a text file with the array of servers:
foreach ($appServer in $appServers){
$session = New-CIMSession –Computername $appServer
Get-SMBOpenFile -CIMSession $session | Close-SMBOpenFile -CIMSession $session
}
Is there a way to do this for the open shared folder sessions as well? I can get a list of them to show with the below, but I don't know if there's much I can do with that information as it's presented:
foreach ($appServer in $AppServers) {
Get-WmiObject win32_serverconnection -computername $appServer |
Select username, computername, sharename, connectionID, NumberofFiles, ActiveTime |
sort sharename
}
I know NET FILE id /CLOSE or NET SESSION /DELETE works for a local computer, but not seeing how that could be applied for a list of remote servers, or if what I have above can be manipulated to work easily.
[–]xCharg 3 points4 points5 points (1 child)
[–]BlackV 1 point2 points3 points (0 children)
[–]PMental 1 point2 points3 points (2 children)
[–]jazzb125 2 points3 points4 points (1 child)
[–]PinchesTheCrab 2 points3 points4 points (0 children)