This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Powershell script works locally but not under SAM component

Below is the script which works locally under PowerShell ISE. But same under SAM Component (ie. Windows PowerShell monitor) it's not working.

Script checks for doc file under path1 and if exist. It takes copy of the file from path1 and move to Path2 by renaming with timestamp.

$directory = 'path1'
$filter = '*.doc'
$msg = ' '
$com = ","
$count = 0
$stamp = Get-Date -F yyyy-MM-dd_HH-mm
Get-ChildItem -Path $directory -Filter $filter | Foreach-Object {
   $msg = $msg + $com + $_.FullName
   $dest = "path1" + $_.Name
   $newName = "path1" + "$($_.BaseName)_$stamp$($_.Extension)"
   Copy-Item -Path $_.FullName -Destination $newName
   $count = $count + 1
}
if($count -gt 0) {
   write-host 'Statistic.FileMonitor:' $count;
   write-host "Message.FileMonitor: $count file found and moved, Filenames- $msg"
   exit 0
} else {
   write-host 'Statistic.FileMonitor:' $count;
   write-host "Message.FileMonitor: $count files found, Filenames- $msg"
   exit 0
}

When execution mode is set as Local Host. It execute. But it says no file found. Even though file exist under path1.

When execution mode is set as Remote. I am getting result as Down.