#powershell #office365
#powershell #office365
Вопрос:
Я уверен, что сделал что-то не так, но я играю с доступом к нескольким командным устройствам office 365, и это работает нормально, но я хочу добавить пользовательские столбцы в мое представление сетки. В 1 столбце указано «Имя клиента», в другом — что-то еще. Это то, что у меня есть до сих пор.
# 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
Ответ №1:
Ключ в том, куда отправлять объекты Out-GridView
.
Это должно помочь вам достичь желаемого:
$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