So I always like to show splatting PowerShell commands when I am presenting sessions or workshops and realised that I had not really blogged about it. (This blog is for @dbafromthecold who asked me to )
What is Splatting?
Well you will know that when you call a PowerShell function you can use intellisense to get the parameters and sometimes the parameter values as well. This can leave you with a command that looks like this on the screen
Start-DbaMigration -Source $Source -Destination $Destination -BackupRestore -NetworkShare $Share -WithReplace -ReuseSourceFolderStructure -IncludeSupportDbs -NoAgentServer -NoAudits -NoResourceGovernor -NoSaRename -NoBackupDevices
$startDbaMigrationSplat = @{ Source = $Source NetworkShare = $Share NoAgentServer = $true NoResourceGovernor = $true WithReplace = $true ReuseSourceFolderStructure = $true Destination = $Destination NoAudits = $true BackupRestore = $true NoSaRename = $true IncludeSupportDbs = $true NoBackupDevices = $true } Start-DbaMigration @startDbaMigrationSplat
Best thing i learned at #SqlSatIceland... #PowerShell "splatting"
Byebye lines of code i no longer need!
Thanks @sqldbawithbeard @cl @dbachecks pic.twitter.com/a3PCkAeaV5— Jan Mulkens (@JanMulkens) March 10, 2018
Install-Module EditorServicesCommandSuite -Scope CurrentUser
# Place this in your VSCode profile Import-Module EditorServicesCommandSuite Import-EditorCommand -Module EditorServicesCommandSuite