I wrote a custom script to look for old files on a shared directory. I tested it out and everything works fine on my machine so I go to create it as a template in SW. If I use the \\server\path method it fails but if I call a directory it passes no problem. This is a CIFS share on a netapp device so I have to call it with a UNC. Any thoughts why it works in powershell but fails in SW? I'd understand it if there was a formatting issue but since the exact same script works if I use a local directory I know it's not a formatting issue.
The error I get when calling a UNC name is as follows (substituted \\Server\Path for the actual path)
Get-ChildItem : An object at the specified path \\Server\Path does not exist. At line:10 char:27 + $FileCount = Get-ChildItem <<<< $PathExt | where {$_.Lastwritetime -lt (date).addminutes(- $minutes)} + CategoryInfo : ObjectNotFound: (\\Server\path:String) [Get-ChildItem], IOException + FullyQualifiedErrorId : ItemDoesNotExist,Microsoft.PowerShell.Commands.GetChildItemCommand
\\Server\Path\*.txt, 2 (should look for any txt file in that path older than 2 minutes)
#Powershell script to identify the number of files of a certain extension older than a certain number of minutes.
#The script uses two variables
#The first variable should be the path\extension C:\*.txt
#The second variable should be the number of minutes before a file is determined to be old
$PathExt = $args.get(0)
$minutes = $args.get(1)
$FileCount = Get-ChildItem $PathExt | where {$_.Lastwritetime -lt (date).addminutes(- $minutes)}
If($FileCount -eq $null)
{
$FileCount = '0'
}
Else
{
If($FileCount.Count -eq $null)
{
$FileCount = '1'
}
Else
{
$FileCount = $FileCount.count
}
}
Write-Host 'Statistic: ' $FileCount
#Write-Host 'Message: ' Number of files greater than $minutes minutes in the following path $pathext
exit(0)