Answered by:
Variable Scope in a fuctions

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 $strFunLogIt_final
Thanks in advance.
Regards,
Divyansh
Divyansh
- Edited by Divyansh_Saxena Tuesday, August 16, 2016 12:40 PM
- Moved by Dave PatrickMVP Tuesday, August 16, 2016 12:48 PM
Tuesday, August 16, 2016 12:38 PM
Answers
-
The PowerShell forum is over here:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=winserverpowershell
I recommend reading this before posting over there:
https://technet.microsoft.com/en-us/library/hh847849.aspx
- Proposed as answer by Dave PatrickMVP Tuesday, August 16, 2016 1:16 PM
- Marked as answer by Dave PatrickMVP Thursday, August 25, 2016 1:21 AM
Tuesday, August 16, 2016 12:53 PM
All replies
-
I'd try them over here.
https://social.msdn.microsoft.com/Forums/en-US/home?category=vslanguages
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.Tuesday, August 16, 2016 12:48 PM -
The PowerShell forum is over here:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=winserverpowershell
I recommend reading this before posting over there:
https://technet.microsoft.com/en-us/library/hh847849.aspx
- Proposed as answer by Dave PatrickMVP Tuesday, August 16, 2016 1:16 PM
- Marked as answer by Dave PatrickMVP Thursday, August 25, 2016 1:21 AM
Tuesday, August 16, 2016 12:53 PM