Home Forums Programming Powershell Problem copying .bak with "$" in file path/name (PS running in SQL job step) RE: Problem copying .bak with "$" in file path/name (PS running in SQL job step)

  • When using double quotes (") PowerShell looks to replace variables with their values whereas if you use single quotes (') it does not. So as you used double quotes it interpreted $instname as a variable, for example.

    If you have no embedded variables then you can use the following:

    $from = '\\srvrname\r$\SQL\MSSQL10_50.instname\MSSQL\Backup\srvrname$instname\DBNAME\FULL\srvrname$instname_DBNAME_FULL_' + $dd + "*.BAK"

    Or you can escape the dollar signs ($) with a grave accent (`) like this:

    $from = "\\srvrname\r`$\SQL\MSSQL10_50.instname\MSSQL\Backup\srvrname`$instname\DBNAME\FULL\srvrname`$instname_DBNAME_FULL_" + $dd + "*.BAK"

    The following should work too:

    $from = "\\srvrname\r`$\SQL\MSSQL10_50.instname\MSSQL\Backup\srvrname`$instname\DBNAME\FULL\srvrname`$instname_DBNAME_FULL_$dd*.BAK"

    Hope this helps.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!