从另一个power shell脚本调用Powershell函数可以使用错误提示

时间:2018-02-26 23:47:06

标签: function powershell scripting

大家好我有以下脚本调用另一个发送电子邮件的脚本。第一个脚本是:

#check status of scheduler
function Check_Scheduler{param([int]$filename) 
if($filename -eq 33)
{
  $Scheduler="Process_F33"
}
elseif($filename -eq 07)
{
 $Scheduler="Process_F07"
 }
$status=(Get-ScheduledTask | Where TaskName -EQ $Scheduler).State 
#read from a text file
$startTime=(Get-Content -Path E:\AshimTest\time.txt) 
$endTime = Get-Date -format HH:mm:ss
#calculate time difference
$TimeDiff = New-TimeSpan $startTime $endTime
if ($TimeDiff.Hours -lt 0) {
   $Hrs = ($TimeDiff.Hours) + 23
   $Mins = ($TimeDiff.Minutes) + 59
   $Secs = ($TimeDiff.Seconds) + 59 }
else {
$Hrs = $TimeDiff.Hours
$Mins = $TimeDiff.Minutes
$Secs = $TimeDiff.Seconds }
$Difference = '{0:00}:{1:00}:{2:00}' -f $Hrs,$Mins,$Secs

if($status -eq "Running")
{
    if ($Hrs -gt 2)
     {
        #Stop-ScheduledTask -TaskName $Scheduler
        echo "Sending email"
         . .E:\AshimTest\GroupEmail.ps1; Send-Mail -group "IT" -bodypath 
"E:\AshimTest\Body.txt" -subject "$Scheduler scheduler Process Failed"
      }
}

}

一切运行正常,我也收到了电子邮件发送,但是当我从powershell ISE运行它时,我得到以下错误,即使脚本工作正常并且做了它必须做的事情。

. : The term '.E:\AshimTest\GroupEmail.ps1' is not recognized as the name of 
a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if 
a path was included, verify that the path is correct and try again.
At E:\AshimTest\Check_Status.ps1:35 char:16
+              . .E:\AshimTest\GroupEmail.ps1; Send-Mail -group "IT" -
bodypath "E: ...
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: 
(.E:\AshimTest\GroupEmail.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

我在PowerShell ISE中遇到这个错误,但脚本仍能正常运行,我是否需要担心或者我有什么不对的选择。我是PowerShell的初学者。

0 个答案:

没有答案