# If there's an error in a call such as $cfg.LockServerSettings(), it is important that the script stops. # Continuing while another application is also potentially modifying settings may corrupt them. # Alternately, your script can also handle errors in a Try/Catch block. $ErrorActionPreference = "Stop" # Check BssCfgManip.htm in your SSH Server installation directory for the correct COM object name for your installation. # The PowerShell instance executing this script needs to run elevated, as administrator, to access SSH Server settings. $cfg = new-object -com "BssCfg726.BssCfg726" # 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.LockServerSettings() $cfg.LoadServerSettings() # Find a virtual account named "Test" (case insensitive), and import into its entry the public key in C:\Path\To\Key.pub. Foreach ($account in $cfg.settings.access.virtAccounts) { If ($account.virtAccount -eq "Test") { $account.auth.keys.Import("C:\Path\To\Key.pub") } } $cfg.SaveServerSettings() $cfg.UnlockServerSettings()