Setting SFTPRoot for PowerShell Server from the command line

If you've enabled SFTP support for PowerShell Server for Windows, you can view or alter the location for the root directory to which users will be connected when they establish an SFTP connection by bringing up the control panel for the PowerShell Server by double-clicking on the "Start PowerShell Server" shortcut in the directory where you installed the application or finding it in the list of apps and then clicking on the Other tab and changing the value for "Root Directory" in the "SFTP Settings" section. Or, alternatively, if you need to view and/or alter the setting from the command line you can use the reg query command to query the value for SFTPRootDir in the Windows Registry or the reg add command to change the value, which is stored in SFTPRootDir under HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer.

Checking the location for SFTPRootDir:

C:\>reg query HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer /v SFTPRootDir

HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer
    SFTPRootDir    REG_SZ    C:\Program Files\SSH\PowerShell Server V6\sftproot

If I wanted to change the location to C:\Users\Public\Documents to allow all user accounts access to read and write files to the directory via SFTP, I could use the reg add command below:

C:\>reg add HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer /v SFTPRootDir /t REG_SZ /d C:\Users\Public\Documents
Value SFTPRootDir exists, overwrite(Yes/No)? yes
The operation completed successfully.

If you don't want to be prompted as to whether you really want to make the change you can add the /f argument to force overwriting the existing registry entry without a prompt asking you if you want to overwrite it, e.g., reg add HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer /v SFTPRootDir /t REG_SZ /d C:\Users\Public\Documents /f.

If you change the location by directly altering the registry value, the GUI will still show the default location even if you restart the SSH/SFTP service by clicking on the Restart option. You can verify that the new value was set with the reg query command:

C:\>reg query HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer /v SFTPRootDir

HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShellServer
    SFTPRootDir    REG_SZ    C:\Users\Public\Documents

When you change the registry value, the next SFTP connection you make to the system will use the new location; you don't have to restart the SFTP service.

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px

Valid HTML 4.01 Transitional

Created: Wednesday January 7, 2015