I am trying to write a script that will look through a set of folders and keep only the last 10 files. The files in each folder could be created daily, weekly or monthly. I
How to call this GCI command in SQL server , was trying below code but returning error
declare @deleteoldtempxe nvarchar(1000)
set @deleteoldtempxe='powershell.exe gci '+''''+ 'I:\New folder\'+''''+' -Recurse| where{-not $_.PsIsContainer}| sort CreationTime -desc|
select -Skip 1| Remove-Item -Force'
select @deleteoldtempxe
EXEC master.dbo.xp_cmdshell @deleteoldtempxe