Quantcast
Channel: THWACK: Popular Discussions - Script Lab
Viewing all articles
Browse latest Browse all 9937

PowerShell script won't return results

$
0
0

I'm trying to get a count of files in a directory that are over 30 minutes old.  Unfortunately, when I test the script output I just sit and wait on an indefinitely spinning wheel--not even an error or a 0.

When I run the script in PowerShell from the poller it appears to work, so I think the problem is in passing down arguments.  I haven't written many scripts for SolarWinds.  Can someone tell me what I'm doing wrong here? 

 

Arguments:

-time 30 -ext txt -path \\server\directory\

 

Script body:

param(

[int]$time,

[string]$ext,

[string]$path)

 

$count = 0

Foreach ($file in Get-ChildItem $path -Filter *.$ext -recurse)

{

    if ($file.LastWriteTime -lt (Get-Date).AddMinutes(-$time))

    {

        $count = $count + 1

    }

}

write-host "statistic:" $count


Viewing all articles
Browse latest Browse all 9937

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>