I'm sure i've done something wrong, but i'm playing around with accessing multiple office 365 powershells and it works fine, but I want to add custom columns in my grid view. 1 column saying "Client Name" another saying something else. This is what I've got so far.
# Prompt For Login
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Email Address'
$msg = 'Enter your email address:'
$emailAddress = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
# Connect Office 365
if (Get-Module -ListAvailable -Name ExchangeOnlineManagement) {
Write-Host "Module Exists"
} else {
Write-Host "Module Does not Exist, Installing..."
Install-Module ExchangeonlineManagement
}
$clients = @("ClientA",
"ClientB",
"ClientC",
"ClientD",
"ClientE")
$client = $clients | Out-GridView -Title "Choose a Client" -Passthru
# Make The Connection
Connect-ExchangeOnline -UserPrincipalName $emailAddress -ShowProgress $true -DelegatedOrganization $client
The key is to send objects to Out-GridView
.
This should help you get where you want:
$clients = [PSCustomObject] @{Client="ClientA";OtherData='Something'},
[PSCustomObject] @{Client="ClientB";OtherData='You'},
[PSCustomObject] @{Client="ClientC";OtherData='Want'},
[PSCustomObject] @{Client="ClientD";OtherData='To'},
[PSCustomObject] @{Client="ClientE";OtherData='Show'}
$choice= $clients | Out-GridView -Title "Choose a Client" -Passthru
#the output from Out-Gridview is now an object, so use dot-notation to get the client.
Connect-ExchangeOnline -UserPrincipalName $emailAddress -ShowProgress $true -DelegatedOrganization $choice.Client