# This script renames a virtual group in SSH Server settings and updates virtual accounts accordingly # Compatible with SSH Server versions 9.xx $virtGroupNameOld = "Virtual Users" $virtGroupNameNew = "#10 Virtual Users" # If there's an error in a call such as $cfg.keypairs.Lock(), it is important that the script stops. # Continuing while another application is also potentially modifying settings may corrupt them. $ErrorActionPreference = "Stop" # 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() # Find the matching virtual group and rename it $grp = $cfg.settings.access.virtGroups.FirstWhere1("group eq ?", $virtGroupNameOld) $grp.group = $virtGroupNameNew # Find virtual accounts that reference the group and update them $accts = $cfg.settings.access.virtAccounts.AllWhere1("group eq ?", $virtGroupNameOld) foreach ($acct in $accts) { $acct.group = $virtGroupNameNew } # Save and unlock settings $cfg.settings.Save() } finally { $cfg.settings.Unlock() }