Dropbox comes in handy as a way of distributing files across systems. You can easily get files to a whole fleet of computers and then use PowerShell to automate tasks.
If you ever wanted to run Dropbox as a Windows Service so it starts with Windows before a user logs in, follow the instructions below.
But first you need this tool srvany
- Delete the Dropbox service:
sc delete "Dropbox Service"
- Run the following command:
sc create Dropbox binPath= "C:\...\srvany.exe" DisplayName= "Dropbox Service"
- Choose properties on Dropbox service > Click on tab “Log On” > Click “This account“, and select the appropriate account in order to run dropbox > Set appropriate password > Set startup type to “Automatic“.
- Run in PowerShell:
New-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dropbox\Parameters New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dropbox\Parameters -Name Application -PropertyType String -Value "C:\Program Files (x86)\Dropbox\Client\Dropbox.exe"
- Go back to Services, and start the Dropbox service
Then, you can incorporate Dropbox into PowerShell by finding the correct Dropbox location and Dropbox path in Windows automatically using PowerShell. The PowerShell below will assign the correct Dropbox path to a variable $dropboxpath which you can use throughout your PowerShell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Dropbox path | |
$dropboxDBfile = Get-ChildItem –Path $env:USERPROFILE\AppData\Local –Recurse –ErrorAction SilentlyContinue | ? {$_.Name -eq 'host.db'} | |
$base64path = gc $dropboxDBfile.FullName | select –index 1 # -index 1 is the 2nd line in the file | |
$dropboxPath = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($base64path)) # convert from base64 to ascii | |
#endregion |
Don’t forget you can Windows Remote Management / Remote PowerShell to manage your Windows workloads remotely. If you need to setup Remote PowerShell, you can follow my guide.