# 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" # This sample assumes some input data which we initialize as an example here $usersWithNewPasswords = @{} $usersWithNewPasswords["User2"] = "Pass2" $usersWithNewPasswords["User3"] = "Pass3" # Describe Windows group settings entries nicely function DescribeGroup { param($group) $gt = $cfg.enums.groupType if ($group.groupType -eq $gt.everyone ) { return "Windows group Everyone" } if ($group.groupType -eq $gt.local ) { return "Windows local group '$($group.group)'" } if ($group.groupType -eq $gt.domain ) { return "Windows domain group '$($group.winDomain)\$($group.group)'" } return "[Unrecognized Windows group type]" } # 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() $groups = $cfg.settings.access.winGroups.entries foreach ($group in $groups) { $shares = $group.session.shares.entries foreach ($share in $shares) { if ($share.specifyCredentials) { $pass = $usersWithNewPasswords[$share.username] if ($pass -ne $null) { $groupDesc = DescribeGroup $group Write-Host "Updating password for share user '$($share.username)' in $groupDesc" $share.password.Set($pass) } } } } $cfg.settings.Save() } finally { $cfg.settings.Unlock() }