Powershell script not recognizing my function

后端 未结 2 1490
予麋鹿
予麋鹿 2020-12-09 09:55

I have a powershell script that parses a file and send an email if it detects a certain pattern. I have the email code setup inside a function, and it all works fine when I

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 10:39

    Powershell processes in order (top-down) so the function definition needs to be before the function call:

    function email($text){
        #email $text
    }
    
    #Do things | 
    foreach{
        email($_)
    }
    

    It probably works fine in the ISE because you have the function definition in memory still from a prior run or test.

提交回复
热议问题