我寫了一個動態的SQL來構建以下查詢,並在SQL Server中使用xp_cmdshell
位置參數無法找到接受的說法
POWERSHELL -command "$d = Get-Date Get-childItem "c:\ServerManagement\Logs\SQL Server Agent" -recurse -include *.log | Where {($_.lastwritetime -le $d.Addhours(-120))} | Remove-Item -Force"
,但是當我在命令提示符下運行它,我得到這個執行它錯誤:
Get-ChildItem : A positional parameter cannot be found that accepts argument 'Agent'.
At line:1 char:19
+ ... = Get-Date; Get-childItem c:\ServerManagement\Logs\SQL Server Agent - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
我的目的是運行上面的代碼與作業類型爲「的CmdExec」一個SQL Server代理作業
我在PowerShell和couldn初學者不知道如何解決上述錯誤。
從Powershell ISE窗口執行PowerShell代碼工作得很好。 -
任何幫助表示讚賞。
(產地評論在回答能夠顯示代碼) –