# If there's an error in a call such as $cfg.settings.Lock(), it is important that the script stops. # Continuing while another application is also potentially modifying settings may corrupt them. $ErrorActionPreference = "Stop" # This function resets file sharing settings for all mount points in a Windows or virtual account or # group settings entry to use global defaults configured in Advanced SSH Server settings > File transfer function ResetMountPointFileSharing { param($accountOrGroup) $nrChanged = 0 foreach ($mountPoint in $accountOrGroup.xfer.mountPoints.entries) { if ($mountPoint.fileSharingBeh -ne 0) { $mountPoint.fileSharingBeh = 0 # $cfg.enums.fileSharingBeh.defaultValue ++$nrChanged } } return $nrChanged } # The PowerShell instance executing this script needs to run elevated, as administrator, to access SSH Server settings. $cfg = new-object -com "Bitvise.BssCfg" # Settings must be locked while undergoing change to preserve their integrity. # If you lock settings and do not unlock them, no other process will be able to edit settings until the object is released. $cfg.settings.Lock() try { $cfg.settings.Load() $nrChanged = 0 foreach ($group in $cfg.settings.access.winGroups.entries) { $nrChanged += ResetMountPointFileSharing($group) } Write-Host "File sharing settings reset for $nrChanged mount points defined by Windows groups" $nrChanged = 0 foreach ($account in $cfg.settings.access.winAccounts.entries) { $nrChanged += ResetMountPointFileSharing($account) } Write-Host "File sharing settings reset for $nrChanged mount points defined by Windows accounts" $nrChanged = 0 foreach ($group in $cfg.settings.access.virtGroups.entries) { $nrChanged += ResetMountPointFileSharing($group) } Write-Host "File sharing settings reset for $nrChanged mount points defined by virtual groups" $nrChanged = 0 foreach ($account in $cfg.settings.access.virtAccounts.entries) { $nrChanged += ResetMountPointFileSharing($account) } Write-Host "File sharing settings reset for $nrChanged mount points defined by virtual accounts" $cfg.settings.Save() } finally { $cfg.settings.Unlock() }