LoginSignup
3
4

More than 3 years have passed since last update.

【Office 365】PowerShellでのリスト処理に役立った私的コマンド集(随時更新)

Last updated at Posted at 2019-10-06

はじめに

PowerShellでのリスト処理に役立った私的コマンド集。
随時更新の雑多なコマンド集なので、ある程度記載が増えたら記事分割するかも。

コマンド

以下記事で紹介されているコマンド(fl,ft,Select-Object,Out-GridView

Out-GridViewを初めて知ったときの衝撃といったら。

パブリックフォルダーのパーミッション情報からUserごとのAccessRights属性内の各権限を;区切りで取得する

Get-PublicFolderClientPermission -Identity "\Folder001" |
    Select-Object Identity, User, @{L="AccessRights"; E={$_.AccessRights -join ";"}}

Get-Mailboxの取得結果からEmailAddresses属性内の各アドレスを;区切りで取得する

Get-Mailbox | Select-Object DisplayName, @{L="EmailAddresses"; E={$_.EmailAddresses -join ";"}}

リストをForEach-Objectしたときのループカウントをコンソール画面に出力

コマンド

$counter = 0
Get-MsolUser | ForEach-Object {

    #ForEachさせたい処理

    $counter ++
    Write-Host ($counter) ($_.UserPrincipalName)
}

画面出力

1 liam@contoso.com
2 noah@contoso.com
3 emma@contoso.com
4 olivia@contoso.com
5 ava@contoso.com
6 …
7 …
8 …
9 …
10 …
11 …
… …

取得した現在時刻を文字列と結合させる

作成したリストをCSV出力するときのファイル名定義のときなどに。

$fileName = [String](Get-Date -Format "yyyyMMddTHHmm") + "_export.csv"

CSVからインポートしたリストが必須列を持っているか確認する

#CSVからデータインポート
$ImportedData = Import-Csv import.csv -Encoding Default

#インポートしたデータの列を取得
$ImportedColumnAry = ($ImportedData | Get-Member -MemberType Properties).Name

#必須列を定義
$RequiredColumnAry = @("Verb", "Noun", "Identity", "Property", "Value")

#インポートしたデータが持っていない必須列を抽出
$NotInColumnAry = $RequiredColumnAry | Where-Object {$_ -notin $ImportedColumnAry}

#持っていない必須列が一部ない(すべてある)場合は処理
If($NotInColumnAry.Count){

    Write-Host "インポートしたデータに右記の必須列がありません。: " ($NotInColumnAry -join ", ")
    # //一部ない場合の処理//

}else{

    Write-Host "インポートしたデータはすべての必須列を持っています。"
    # //すべてある場合の処理//

}

リストの列・行を変換する

コマンド

Get-OrganizationConfigの場合。

$Result = Get-OrganizationConfig
($Result | Get-Member -MemberType Properties).Name |
    Select-Object @{L="Property"; E={$_}}, @{L="Value"; E={$Result.$_}}

結果

Property                                                  Value
--------                                                  -----
PSComputerName                                            outlook.office365.com
PSShowComputerName                                        False
RunspaceId                                                xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ACLableSyncedObjectEnabled                                False
ActivityBasedAuthenticationTimeoutEnabled                 True
ActivityBasedAuthenticationTimeoutInterval                06:00:00
ActivityBasedAuthenticationTimeoutWithSingleSignOnEnabled True
AdfsAudienceUris
AdfsAuthenticationConfiguration
AdfsEncryptCertificateThumbprint
(中略)

以上

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4