How can the System databases in SQL Server 2016 be moved using Powershell? I'm trying to move the system databases using Powershell ie. without using any T-SQL.


Using SMO : 
Install-Module SQL-SMO 
$smo = New-SMO -ServerName localhost
$smo.databases["TempDB"].PrimaryFilePath= "F:\Tempdb\"
$smo.databases["TempDB"].Alter()    gives an error: 


  'PrimaryFilePath' is a ReadOnly property.



The logfile moves fine though. 
$smo.databases["TempDB"].LogFiles[0].Filename = "F:\Tempdb\tempdb.ldf"


Couldn't locate any specific cmdlets in the SQLServer or DBATools modules either. Copy-DbaDatabase comes closest; but not exactly.
The Restore-DbaDatabase in dbatools right now blocks the ability to restore the system databases. It is on the roadmap at some point to work out the process. The block in that command is why Copy-DbaDatabase would fail as well, and you can't move any system database by simple detach/attach method.

Overall it could be worked out to perform the whole task in PowerShell using dbatools commands with a mix of just "manually prepared" code around SMO.