首先,对不起,如果我的英语不是最好的。但我会尽量详细地解释我的问题。
我遇到了一个问题,我不能让Format-Table来实现我给它的输出。
下面是我对atm有问题的部分。
cls
$TotalSize = $($mailboxes. @{name = ”TotalItemSize (GB)”; expression = { [math]::Round((($_.TotalItemSize.Value.ToString()).Split(“(“)[1].Split(” “)[0].Replace(“,”, ””) / 1GB), 2) } });
$UserN = $($mailboxes.DisplayName)
$itemCount = $($mailboxes.ItemCount)
$LastLogonTime = $($mailboxes.ItemCount)
$allMailboxinfo = @(
#lager dataen som skal inn i et objekt
@{Username= $UserN; ItemCount = $itemCount; LastLogonTime = $($mailboxes.ItemCount); Size = $TotalSize}) | % { New-Object object | Add-Member -NotePropertyMembers $_ -PassThru }
$Table = $allMailboxinfo | Format-Table | Out-String
$Table它的输出给了我在表的每个标题下面看起来几乎像json语法的内容。
Username LastLogonTime ItemCount Size
-------- ------------- --------- ----
{username1, username2,username3,userna...} {$null, $null, $null, $null...} {$null, $null, $null, $null...} {$null, $null, $null, $null...}单独运行命令似乎是可行的。像$mailboxes.DisplayName一样,给出了我想要的显示名称的确切数据。即使是在桌子上。
im以这种方式创建表而不是只使用select-object的原因是,稍后我将合并几个表。使用下面脚本中的逻辑。
cls
$someData = @(
@{Name = "Bill"; email = "email@domain.com"; phone = "12345678"; id = "043546" }) | % { New-Object object | Add-Member -NotePropertyMembers $_ -PassThru }
$moreData = @(
@{Name = "Bill"; company = "company 04"}) | % { New-Object object | Add-Member -NotePropertyMembers $_ -PassThru }
$Merge = @(
#plots the data into a new table
@{Name = $($someData.Name); e_mail = $($someData.email); phone = $($someData.phone); id = $($someData.id); merged = $($moreData.company) }) | % { New-Object object | Add-Member -NotePropertyMembers $_ -PassThru }
#formatting table
$Table = $Merge | Format-Table | Out-String
#print table
$Table如果你想知道我怎么处理这个的。总之,我的目标。是使用来自Exchange的信息的表;
DisplayName,TotalItemSize(GB),ItemCount,LastLogonTime,电子邮件地址,存档+ Maxquoata,Quoata为邮箱.
发布于 2021-11-02 13:51:10
您正在创建一个对象,其中每个属性都包含来自原始邮箱对象数组的属性值数组。
相反,每个邮箱创建1个新对象。
# construct output objects with Select-Object
$allMailBoxInfo = $mailboxes |Select @{Name='Username';Expression='DisplayName'},ItemCount,@{Name='LastLogonTime';Expression='ItemCount'},@{Name='Size';Expression={[math]::Round((($_.TotalItemSize.Value.ToString()).Split("(")[1].Split(" ")[0].Replace(",", "") / 1GB), 2) }}
# format table
$Table = $allMailBoxInfo | Format-Table | Out-String
# print table
$Tablehttps://stackoverflow.com/questions/69811353
复制相似问题