param ( [Parameter(Position=0, Mandatory=$true)] [string] $user, [Parameter(Position=1, Mandatory=$true)] [string] $pass, [Parameter(ParameterSetName="Instance")] [string] $instance ) # 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" # The PowerShell instance executing this script needs to run elevated, as administrator, to access SSH Server settings. $cfg = new-object -com "Bitvise.BssCfg" if ($instance) { $cfg.SetInstance($instance) } # 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 specified virtual account $acct = $cfg.settings.access.virtAccounts.FirstWhere1("virtAccount eq ?", $user) if (-not $acct) { Write-Error "A virtual account named $user could not be found in SSH Server settings." } else { $acct.virtPassword.Set($pass) $cfg.settings.Save() Write-Host "Password for SSH Server virtual account $user has been set." } } finally { $cfg.settings.Unlock() }