I have been using PowerShell to automate some administrative functions. A lot of the scripts contain common code and I would like to put this common code into its own separate script (process) The issue I am having, which is understandable, is that variable information in a 'called script' is not available to the main script.
Example ... Main script (Main.ps1)
# This script checks to see if Exchange command are loaded and if not loads them into PowerShell
(This seems to work just fine!)
I have another script that prompts for a Mailbox name (assumed SamAccountName/Alias) is entered
Here is ValidateMailbox.ps1
$Temp = Read-Host 'Please enter the user logon name' -ErrorAction SilentlyContinue
$Mailbox = Get-Mailbox $Temp
$Logon = "error"
$Logon = "good"
While ($Logon -eq "error")
When I run these commands inside the 'main' script everything works fine. If I call the ValidateMailbox.ps1; I am prompted to enter data however the information stored in $Mailbox is not available ... I know this doesn't extend outside the scope of the script from which is run.
I have found lots of examples of passing parameters TO a script but can't seem to find a solution where a called script passes $variables back to the 'Main' script.