Keep x number of files and delete all others - Powershell

前端 未结 4 667
天命终不由人
天命终不由人 2020-12-15 18:01

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

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 18:34

    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
    

提交回复
热议问题