We help IT Professionals succeed at work.

global Variable - 2 functions in powershell

264 Views
Last Modified: 2017-04-10
Hi All,

I have two functions one which sets a global variable and the other with calls the global variable. however the second function do not recognise the global variable, please help!

1st function:

$Window.FindName("SelectMailbox").Add_Click( {
    param (
        [Object]$Sender,

        [System.Windows.RoutedEventArgs]$EventArgs
    )

    $ListView = $Sender.FindName('MailboxesList')
    
    if ($null -ne $ListView.SelectedItems) {
        $ListView.ItemsSource = @($ListView.SelectedItems | Select-Object DisplayName, TotalItemSize, ItemCount, Database, TotalDeletedItemSize,DeletedItemCount, LastLoggedOnUserAccount, LastLogonTime, LastLogoffTime -OutVariable mailboxtomigrate)
		$m = $mailboxtomigrate | select DisplayName | Out-String
		Set-Variable -Name $m -Scope Global
		
    }
} )

Open in new window


2nd function:

$Migrate.Add_Click({


[System.Windows.MessageBox]::Show("$m")

})

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.