'PowerShell 5.1 and sqlcmd.exe - Is there a way to pass arguments to a string query?

Environment:
Windows Server 2016 Standard
Windows 10 Pro
PowerShell 5.1

Is there a way to pass arguments to a string query (instead of an -i input.sql)? I don't have Invoke-Sqlcmd available to me either. The following does not recognize arg1 in the print statement.

$test = sqlcmd -v arg1='hello_world' -E -Q "SET NOCOUNT ON; 
print $(arg1)" -W -h -1 -d database1 -S "(localdb)\ProjectsV13" 
Write-Output $test


Solution 1:[1]

This seems to work:

$x="hello"
$sql = "print '$x'"
Write-Output $sql
$test = sqlcmd -E -Q $sql -W -h -1 -d database1 -S "(localdb)\ProjectsV13" 
Write-Output $test

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rod