Microsoft Graph PowerShell SDK を使用したライセンス管理操作

こちらに対応すべくメモ

jpazureid.github.io

$credential = Get-Credential
Import-Module ExchangeOnlineManagement
Connect-MgGraph -Scopes "Organization.Read.All","User.ReadWrite.All"
Import-Module Microsoft.Graph.Users
Connect-ExchangeOnline -Credential $credential

Import-Csv "C:\PoweShell\NewUsers_202207.csv" | 
    ForEach-Object `
        {`
             New-MgUser `
                -AccountEnabled `
                -CompanyName $_.CompanyName `
                -Department $_.Department `
                -DisplayName $_.DisplayName `
                -GivenName $_.GivenName `
                -EmployeeId $_.EmployeeId `
                -JobTitle $_.JobTitle `
                -MailNickName $_.MailNickName `
                -MobilePhone $_.MobilePhone `
                -PasswordProfile @{"Password" = $_.Password;ForceChangePasswordNextSignIn = $false;forceChangePasswordNextSignInWithMfa = $false} `
                -PasswordPolicies "DisablePasswordExpiration" `
                -Surname $_.Surname `
                -UsageLocation "JP" `
                -UserPrincipalName $_.UserPrincipalName `
         }

$License1 = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphAssignedLicense `
                       -Property @{SkuId = "f245ecc8-75af-4f8e-b61f-27d8114de5f3"; DisabledPlans = @("8c7d2df8-86f0-4902-b2ed-a0458298f3b3","39b5c996-467e-4e60-bd62-46066f572726","54fc630f-5a40-48ee-8965-af0503c1386e","0feaeb32-d00e-4d66-bd5a-43b5b83db82c","199a5c09-e0ca-4e37-8f7c-b05d533e1ea2","5bfe124c-bbdc-4494-8835-f1297d457d79","31b4e2fc-4cd6-4e7d-9c1b-41407303bd66","a23b959c-7ce8-4e57-9140-b90eb88a9e97","7547a3fe-08ee-4ccb-b430-5077c5041653")}

Import-Csv -Path "C:\PoweShell\NewUsers_202207.csv" | 
    ForEach-Object `
        {`
            Set-MgUserLicense `
                -UserId $_.UserPrincipalName `
                -AddLicenses @($License1) `
                -RemoveLicenses @() `
}
Import-Csv -Path "C:\PoweShell\NewUsers_202207.csv" | 
    ForEach-Object `
        {`
            Set-User `
            	-Identity $_.UserPrincipalName `
            	-PhoneticDisplayName $_.Furigana `
		}

Import-Csv -Path "C:\PoweShell\NewUsers_202207.csv" | 
    ForEach-Object `
        {`
			Set-MailboxRegionalConfiguration `
				-Identity $_.UserPrincipalName `
				-Language "ja-JP" `
				-DateFormat "yyyy/MM/dd" `
				-TimeFormat "HH:mm" `
				-TimeZone "Tokyo Standard Time" `
				-LocalizeDefaultFolderName `
		}

Import-Csv -Path "C:\PoweShell\NewUsers_202207.csv" | 
    ForEach-Object `
        {`
			Set-MailboxFolderPermission `
			    -Identity $_.Calendar `
			    -User "既定" `
			    -AccessRights LimitedDetails `
		}

#マネージャー
#グループ

ポータルサイトをダウンロードさせる

$WshShell = New-Object -comObject WScript.Shell
$DesktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)
$Shortcut = $WshShell.CreateShortcut("$DesktopPath\ポータル サイト を入手 - Microsoft Store ja-JP.URL")
$Shortcut.TargetPath = "https://www.microsoft.com/ja-jp/p/company-portal/9wzdncrfj3pz?activetab=pivot:overviewtab"
$Shortcut.Save()

【PowerShell】Microsoft 365管理 ~連絡先~

連絡先編集のメモ


記載がないAll Groupsグループ(チーム)一覧

 ((Alias -ne `$null) -and (RecipientTypeDetailsValue -eq 'GroupMailbox'))

記載がないOffline Global Address Listオフライン グローバル アドレス一覧

((Alias -ne `$null) -and (((((((((((ObjectClass -eq 'user') -or (ObjectClass -eq 'contact'))) -or (ObjectClass -eq'msExchSystemMailbox'))) -or (ObjectClass -eq 'msExchDynamicDistributionList'))) -or (ObjectClass -eq 'group')))-or (ObjectClass -eq 'publicFolder'))))

アレンジ

((Alias -ne `$null) -and (((((((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (-not(Database -ne `$null)) -and (-not(ServerLegacyDN -ne `$null)))) -or (((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (((Database -ne `$null) -or (ServerLegacyDN -ne `$null))))))) -and (-not((RecipientTypeDetailsValue -eq 'GroupMailbox') -or (RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox') -or (ResourceType -eq 'Equipment') -or (RecipientTypeDetails -eq 'GuestMailUser')))))) #All Users社内アドレス一覧

((Alias -ne `$null) -and ((ObjectCategory -like 'person' -and ObjectClass -eq 'contact') -or (ObjectCategory -like 'person' -and ObjectClass -eq 'user' -and RecipientTypeDetails -eq 'GuestMailUser'))) #All Contacts社外アドレス一覧

((Alias -ne `$null) -and (ObjectCategory -like 'group') -and (RecipientTypeDetails -ne 'GroupMailbox')) #All Distribution Listsメーリングリスト一覧

((Alias -ne `$null) -and (ResourceType -eq 'Equipment')) #Public Folder備品一覧

【PowerShell】Microsoft 365管理 ~ユーザー追加~

ユーザー追加をする時の個人的メモ
$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
Connect-AzureAD -Credential $UserCredential
Connect-ExchangeOnline -Credential $UserCredential

Get-MsolAccountSku

$disabledplans = "Deskless","KAIZALA_O365_P2","MCOSTANDARD","MICROSOFTBOOKINGS","PROJECT_O365_P2","SWAY","YAMMER_ENTERPRISE","O365_SB_Relationship_Management" #"KAIZALA_O365_P2","MCOSTANDARD","PROJECT_O365_P1","SWAY","YAMMER_ENTERPRISE"
$licenses = New-MsolLicenseOptions -AccountSkuId "xxx:O365_BUSINESS_PREMIUM" -DisabledPlans $disabledplans #xxx:O365_BUSINESS_ESSENTIALS

Import-Csv "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | 
	ForEach `
		{`
			New-MsolUser `
				-UserPrincipalName $_.UserPrincipalName `
				-FirstName $_.FirstName `
				-LastName $_.LastName `
				-DisplayName $_.DisplayName `
				-Title $_.Title `
				-Department $_.Department `
				-PhoneNumber $_.PhoneNumber `
                		-LicenseAssignment xxx:O365_BUSINESS_PREMIUM `
                		-LicenseOptions $licenses `
                		-UsageLocation JP `
				-ForceChangePassword $False `
        } `
| Export-Csv -Path "C:\Users\xxx\Desktop\NewUsersResults__2021☓☓.csv" -Encoding UTF8

Import-Csv -Path "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | 
	ForEach `
        	{`
            		Set-AzureADUser `
                		-ObjectId $_.UserPrincipalName `
				-CompanyName $_.CompanyName `
		}

Import-Csv -Path "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | 
	ForEach `
		{`
			Set-AzureADUserExtension `
				-ObjectId $_.UserPrincipalName `
				-ExtensionName employeeId `
				-ExtensionValue $_.ExtensionValue `
		}

Import-Csv -Path "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | 
	ForEach `
		{`
			Set-User `
            			-Identity $_.UserPrincipalName `
            			-PhoneticDisplayName $_.Furigana `
		}

Import-Csv -Path "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | 
	ForEach `
        	{`
			Set-MailboxRegionalConfiguration `
				-Identity $_.UserPrincipalName `
				-Language "ja-JP" `
				-DateFormat "yyyy/MM/dd" `
				-TimeFormat "HH:mm" `
				-TimeZone "Tokyo Standard Time" `
				-LocalizeDefaultFolderName `
		}

Import-Csv -Path "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | 
	ForEach `
        	{`
			Set-MailboxFolderPermission `
			-Identity $_.Calendar `
			-User "既定" `
			-AccessRights LimitedDetails `
		}

Import-CSV "C:\Users\xxx\Desktop\NewUsers_2021☓☓.csv" | Foreach {Set-Mailbox -Identity $_.UserPrincipalName -EmailAddresses @{Remove="smtp:$($_.Alias)"}} 

マネージャー
グループ

【VBA】~番外編~

Dim wslist As Worksheet
Dim result, s, e, time, i As Long
Dim attached1 As String
Dim outlookObj As Outlook.Application
Dim mailItemObj As Outlook.mailItem
Dim myattachments As Outlook.Attachments

Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)

Sub 連続送信マクロ()

result = MsgBox("連続送信を実行しますか?", vbYesNo + vbExclamation)

If result = vbYes Then

    Set wslist = ThisWorkbook.Worksheets(1)

    attached1 = wslist.Range("I4").Value

    s = wslist.Range("B3").Value
    e = wslist.Range("C3").Value
    time = 2000
        
        For i = s To e
            
            wslist.Range("A3").Value = i
            
            Set outlookObj = New Outlook.Application
            Set mailItemObj = outlookObj.CreateItem(olMailItem)
            Set myattachments = mailItemObj.Attachments
                
                With mailItemObj
                    
                    .To = wslist.Range("F1").Value
                    .CC = wslist.Range("F2").Value
                    .Subject = wslist.Range("F3").Value
                    .BodyFormat = olFormatHTML
                    .Body = wslist.Range("F4").Value & vbCrLf & _
                            wslist.Range("F5").Value & vbCrLf & _
                            wslist.Range("F6").Value & vbCrLf & _
                            wslist.Range("F7").Value & vbCrLf & _
                            wslist.Range("F8").Value

                    If attached1 = "" Then
                        GoTo Label1
                    End If
                    
                    myattachments.Add attached1

Label1:
    .Display
    '.Send
                     
                End With

            Sleep time
            
        Next i
 
    Set outlookObj = Nothing

    MsgBox "送信完了"

Else

    Exit Sub
    
End If
 
End Sub

【PowerShell】Microsoft 365管理 ~DKIM編~

カスタムドメインを取得してExchangeOnlineを運用する際のTips

カスタム ドメインDKIM をメールに使用する方法 - Office 365 | Microsoft Docs

公式の翻訳

New-DkimSigningConfig -DomainName <domain> -Enabled $false #①
Get-DkimSigningConfig -Identity <domain> | Format-List Selector1CNAME, Selector2CNAME #②
Set-DkimSigningConfig -Identity <domain> -Enabled $true #③