Query sql server from powershell
Query sqlserver
powershell module
Install-Module sqlserver -Force
A minimun nuget version is required. A messages provides the command to install it if was required.
Run query
Invoke-Sqlcmd -Query "SELECT GETDATE() AS TimeOfQuery" -ServerInstance "localhost"
Run script
Invoke-Sqlcmd -InputFile "C:\setupscripts\createUser.sql" | Out-File -FilePath "C:\setupscripts\createUser.log"