Variable Scope in a fuctions RRS feed

  • Question

  • Hello, I have a function "funLogIt" which simply append the current date before the message that is

    passed through $strFunLogIt. Is there a way that I can get all the appended message at the end.

    I am trying to achieve this by concatenating all the messages into $strFunLogIt_final but

    its failing. I believe the scope of the variable “strFunLogIt_final “ is not correct. Can someone please help with in concatenating all the message into one variable?

     $strFunLogIt_final = ""
    Function funLogIt {
        param ($strFunLogIt,$intFunLogIt)
        $strDateTime = (Get-Date).ToString()
    	$strFunLogIt = -join ("$strDateTime", "`t", "$strFunLogIt")
        $strFunLogIt_final = $strFunLogIt_final + $strFunLogIt
        Function funCreateFolder {
        param ($folCreateFolder)    
                funLogIt -strFunLogIt "Creating folder ... $folCreateFolder" -intFunLogIt 0
        funLogIt -strFunLogIt "Status" -intFunLogIt 0
    	funLogIt -strFunLogIt "SQL DB Not Found, nothing to backup" -intFunLogIt 1
        funLogIt -strFunLogIt "Not Found" -intFunLogIt 1
    	funLogIt -strFunLogIt "Backup Aborting..." -intFunLogIt 1

    Thanks in advance.




    Tuesday, August 16, 2016 12:38 PM


All replies