Just a heads up when running the script today I got a missing module error, which is to be expected, as module sqlserver hadn't been installed/imported.
However after doing so (SQLSERVER v. 22.3.0) I got an error saying invoke-sqlcmd was not recognized as a command.
Investigating I found that the command was indeed missing from that particular version, but present in earlier versions.
So removing 22.3.0 with "Uninstall-Module -Name SqlServer -RequiredVersion 22.3.0" and installing an older version with "Install-Module -Name SqlServer -RequiredVersion 21.1.18256 -Force -AllowClobber" (per AI suggestion, so be vary of errors ;-) ) fixed the error and the script now runs as it should.
Just a heads up when running the script today I got a missing module error, which is to be expected, as module sqlserver hadn't been installed/imported.
However after doing so (SQLSERVER v. 22.3.0) I got an error saying invoke-sqlcmd was not recognized as a command.
Investigating I found that the command was indeed missing from that particular version, but present in earlier versions.
So removing 22.3.0 with "Uninstall-Module -Name SqlServer -RequiredVersion 22.3.0" and installing an older version with "Install-Module -Name SqlServer -RequiredVersion 21.1.18256 -Force -AllowClobber" (per AI suggestion, so be vary of errors ;-) ) fixed the error and the script now runs as it should.