# 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" # 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() # Create a new virtual account # Assign it a virtual group # Assign it a password # Assign it a client authentication public key from C:\Path\To\Key.pub $a = $cfg.settings.access.virtAccounts.new $a.virtAccount = "AccountName" $a.group = "Virtual Users" $a.virtPassword.Set("AccountPassword") $a.auth.keys.ImportFromFile("C:\Path\To\Key.pub") # Clear any existing mount points # Disable inheritance of mount points defined in the group settings entry # Alternately, use $true to enable inheritance $a.xfer.mountPoints.Clear() $a.xfer.inheritMountPoints = $false # Create a new mount point which will be accessible at the root of the virtual filesystem ("/") # Map it to C:\SftpRoot\AccountName $m = $a.xfer.mountPoints.new $m.sfsMountPath = "/" $m.allowUnlimitedAccess = $false $m.realRootPath = "C:\SftpRoot\AccountName" $a.xfer.mountPoints.NewCommit() # Create an additional mount point which will be accessible as a virtual subdirectory ("/OtherDir") # Map it to D:\Special\OtherDir $m = $a.xfer.mountPoints.new $m.sfsMountPath = "/OtherDir" $m.allowUnlimitedAccess = $false $m.realRootPath = "D:\Special\OtherDir" $a.xfer.mountPoints.NewCommit() # Commit the new virtual account to settings $cfg.settings.access.virtAccounts.NewCommit() # Save and unlock settings $cfg.settings.Save() } finally { $cfg.settings.Unlock() }