Task schedule don't run ps script

Hi,I can use this ps script to del snapshot.But I added the script to the task schedule and only saw PowerShell running in the process, but the script is not running

`foreach($vm in (Import-Csv C:\automatic\server-name-linuxpro.csv).vmname){
    if(get-vm $vm | Get-Snapshot -Name "linux patch*" ){
        # Write-Host $vm
        if(((get-vm $vm | Get-Snapshot -Name "linux patch*" -ErrorAction SilentlyContinue).Created).adddays(3) -lt (get-date)){
          # Write-Host $vm
           Get-VM -Name $vm |Get-Snapshot -Name "linux patch*" |Remove-Snapshot -Confirm:$false
           "$(get-date): $vm : remove for $(whoami)">> c:\LOG\Snapshot_del.txt

one way to check if the problem is with the script or the task configuration is to replace this script with a simple script, may be a folder creation in a script and see it executes with the same task.

Another tip here is to avoid multiple Get-Vm usages, do it once and save it in a variable and use variable after that.

Try using Start-transcript that way you can check the transcript file and see if the script is doing anything or there might be an error

I have had some issues with our AV solution blocking any scheduled task that invokes PowerShell, make sure it isn’t being blocked by your own AV.

It also might help to share the task details on how you are running the script.