PowerShell自定义列网格视图

PowerShell自定义列网格视图,powershell,office365,Powershell,Office365,我肯定我做错了什么,但我正在尝试访问多个office 365 PowerShell,它工作正常,但我想在我的网格视图中添加自定义列。一列写着“客户名称”,另一列写着别的。这就是我到目前为止得到的 # Prompt For Login [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') $title = 'Email Address' $msg = 'Enter your email addre

我肯定我做错了什么,但我正在尝试访问多个office 365 PowerShell,它工作正常,但我想在我的网格视图中添加自定义列。一列写着“客户名称”,另一列写着别的。这就是我到目前为止得到的

# 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

关键是将对象发送到
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