• i printed the Tsql fron @cmddtring variable which is actually getting executed at last, kindly find the printed or actual executed text of @cmdstring below, i have not added any double quote just pasting same what i am getting.

    ""powershell.exe" "& Get-ChildItem 'D:\Dtest\' | where {$_.lastWriteTime -lt ((Get-Date).AddHours(-6))

    -and ($_.Extension -match 'txt') } | Remove-Item -force "

    below is the error :

    Missing closing '}' in statement block.

    At line:1 char:83

    + & Get-ChildItem 'D:\Dtest\' | where {$_.lastWriteTime -lt ((Get-Date).AddHour

    s(-6)) <<<<

    NULL