I was looking for a purely PowerShell (no regedit or sc.exe) method that can work on 2008R2/Win7 and newer, and came up with this:
Easy one is do the regedit with PowerShell:
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\LanmanWorkstation' -Name DependOnService -Value @('Bowser','MRxSmb20','NSI')
Or, using WMI:
$DependsOn = @('Bowser','MRxSmb20','NSI','') #keep the empty array element at end $svc = Get-WmiObject win32_Service -filter "Name='LanmanWorkstation'" $svc.Change($null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$DependsOn)
The Change method of the Win32_Service class helped point to a solution:
uint32 Change( [in] string DisplayName, [in] string PathName, [in] uint32 ServiceType, [in] uint32 ErrorControl, [in] string StartMode, [in] boolean DesktopInteract, [in] string StartName, [in] string StartPassword, [in] string LoadOrderGroup, [in] string LoadOrderGroupDependencies[], [in] string ServiceDependencies[] );