\u4ee5\u4e0b\u306b\u30a2\u30ab\u30a6\u30f3\u30c8\u767b\u9332\u7528\u306e PowerShell \u3092\u793a\u3057\u307e\u3059\u3002\u30e1\u30e2\u5e33\u306a\u3069\u306b\u30b3\u30d4\u30fc\u3057\u3066\u3001addm365user.ps1 \u3068\u3044\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u4fdd\u5b58\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6709\u52b9\u671f\u9650\u3092\u7121\u671f\u9650\u306b\u3059\u308b (-PasswordPolicies “DisablePasswordExpiration,DisableStrongPassword”)\u3001\u521d\u56de\u30ed\u30b0\u30a4\u30f3\u6642\u306b\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u5909\u66f4\u3092\u8981\u6c42\u3057\u306a\u3044 (“forceChangePasswordNextSignIn” = $false)\u3000\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n
\n###############################################################################################################################
# Name
# addm365user.ps1 – Microsoft 365 \u306b\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u8ffd\u52a0\u3059\u308b
# SYNOPSIS
# addm365user [INPORT FILE]
# DESCRIPTION
# Microsoft 365 \u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u4f5c\u6210\u7528\u306e[INPORT FILE]\u3092\u8aad\u307f\u8fbc\u307f\u3001Microsoft 365 \u306b\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u767b\u9332\u3001
# \u30e9\u30a4\u30bb\u30f3\u30b9\u4ed8\u4e0e\u3092\u3057\u3001AddedNewUsers-YYYY_MM_DD-HH_MM.csv \u306b\u767b\u9332\u7d50\u679c\u3092\u51fa\u529b\u3057\u307e\u3059\u3002
# \u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u5f31\u3044\u30d1\u30b9\u30ef\u30fc\u30c9\u3082\u767b\u9332\u53ef\u80fd\u3067\u3001\u6709\u52b9\u671f\u9650\u3082\u306a\u3057\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u521d\u671f\u30b5\u30a4\u30f3\u6642\u306b\u30d1\u30b9\u30ef\u30fc\u30c9\u5909\u66f4\u3082\u6c42\u3081\u3089\u308c\u307e\u305b\u3093\u3002
# CSV\u306e\u66f8\u5f0f\u306f1\u884c\u76ee\u306b\u30bf\u30a4\u30c8\u30eb\u30012\u884c\u76ee\u4ee5\u964d\u306b\u767b\u9332\u30c7\u30fc\u30bf\u3092\u5165\u529b\u3057\u307e\u3059\u3002
# 1\u884c\u76ee: UserPrincipalName,Password,MailNickname,DisplayName,GivenName,SurName,JobTitle,EmployeeId,EmployeeType,Department,City,State,Country,StreetAddress,PostalCode,SkuId1,SkuId2,SkuId3
# SkuId1\uff5e3 \u306b\u306f\u3001Get-MgSubscribedSku | ft SkuId, SkuPartNumber -Wrap\u3000\u3067\u53d6\u5f97\u3057\u305f SkuId \u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002###############################################################################################################################
Connect-MgGraph -Scopes “User.ReadWrite.All” > $null
Import-Module -Name Microsoft.Graph.Users
date
echo ” Create new users”
$addedtime = Get-Date -format “yyyy_MM_dd-HH_mm”
$outputfilename = “AddedNewUsers-” + $addedtime + “.csv”
Import-Csv -Path $Args[0] -Encoding UTF8 | `
foreach {
$UserPrincipalName = $_.UserPrincipalName
$DisplayName = $_.DisplayName
$MailNickName = $UserPrincipalName.Split(“@”)[0]
$SurName = $_.SurName
$GivenName = $_.GivenName
$JobTitle = $_.JobTitle ; if([string]::IsNullOrEmpty($JobTitle)){$JobTitle = ” “}
$EmployeeId = $_.EmployeeId ; if([string]::IsNullOrEmpty($EmployeeId)){$EmployeeId = ” “}
$EmployeeType = $_.EmployeeType ; if([string]::IsNullOrEmpty($EmployeeType)){$EmployeeType = ” “}
$Department = $_.Department ; if([string]::IsNullOrEmpty($Department)){$Department = ” “}
$City = $_.City ; if([string]::IsNullOrEmpty($City)){$City = ” “}
$State = $_.State ; if([string]::IsNullOrEmpty($State)){$State = ” “}
$Country = $_.Country ; if([string]::IsNullOrEmpty($Country)){$Country = ” “}
$PostalCode = $_.$PostalCode ; if([string]::IsNullOrEmpty($PostalCode)){$PostalCode = ” “}
$StreetAddress = $_.$StreetAddress ; if([string]::IsNullOrEmpty($StreetAddress)){$StreetAddress = ” “}
If([string]::IsNullOrEmpty($GivenName) -or [string]::IsNullOrEmpty($SurName)) {
New-MgUser -AccountEnabled -UserPrincipalName “$UserPrincipalName” -DisplayName “$DisplayName” -MailNickName “$MailNickname” -UsageLocation “JP” -JobTitle “$JobTitle” -EmployeeId “$EmployeeId” -EmployeeType “$EmployeeType” -Department “$Department” -City “$City” -State “$State” -Country “$Country” -PostalCode “$PostalCode” -StreetAddress “$StreetAddress” -PasswordPolicies “DisablePasswordExpiration,DisableStrongPassword” -PasswordProfile @{ “Password”=$_.Password ; “forceChangePasswordNextSignIn” = $false}
}
Else {
New-MgUser -AccountEnabled -UserPrincipalName “$UserPrincipalName” -DisplayName “$DisplayName” -MailNickName “$MailNickname” -SurName “$SurName” -GivenName “$GivenName” -UsageLocation “JP” -JobTitle “$JobTitle” -EmployeeId “$EmployeeId” -EmployeeType “$EmployeeType” -Department “$Department” -City “$City” -State “$State” -Country “$Country” -PostalCode “$PostalCode” -StreetAddress “$StreetAddress” -PasswordPolicies “DisablePasswordExpiration,DisableStrongPassword” -PasswordProfile @{ “Password”=$_.Password ; “forceChangePasswordNextSignIn” = $false}
}
} | Select-Object Id, UserPrincipalName, DisplayName, GivenName, Surname, JobTitle, EmployeeId, EmployeeType, Department, City, State, Country, StreetAddress, PostalCode | Export-Csv -Path $outputfilename -Encoding UTF8
date
echo ” Licensing to users”
Import-Csv -Path $Args[0] -Encoding UTF8 | `
foreach {
$SkuId1 = $_.SkuId1
$License1 = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphAssignedLicense -Property @{SkuId = $SkuId1}
$SkuId2 = $_.SkuId2
$License2 = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphAssignedLicense -Property @{SkuId = $SkuId2}
$SkuId3 = $_.SkuId3
$License3 = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphAssignedLicense -Property @{SkuId = $SkuId3}
if([string]::IsNullOrEmpty($SkuId2)){
$License1 = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphAssignedLicense -Property @{SkuId = $SkuId1}
Set-MgUserLicense -UserId $_.UserPrincipalName -AddLicenses @($License1) -RemoveLicenses @() > $null
}
elseif([string]::IsNullOrEmpty($SkuId3)){
Set-MgUserLicense -UserId $_.UserPrincipalName -AddLicenses @($License1, $License2) -RemoveLicenses @() > $null
}
else {
Set-MgUserLicense -UserId $_.UserPrincipalName -AddLicenses @($License1, $License2, $License3) -RemoveLicenses @() > $null
}
}
Disconnect-MgGraph > $null
date
echo ” Completed”<\/p>\n<\/blockquote>\n\n\n\n
\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u767b\u9332<\/strong><\/p>\n\n\n\naddm365user.ps1 \u3092\u5b9f\u884c\u3057\u3066\u65b0\u898f\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u767b\u9332\u3057\u307e\u3059\u3002\u5165\u529b\u30d5\u30a1\u30a4\u30eb\u306b\u306f\u300c\u30a2\u30ab\u30a6\u30f3\u30c8\u767b\u9332\u7528\u306e CSV \u30d5\u30a1\u30a4\u30eb\u300d\u3067\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n
\naddm365user.ps1 <\u5165\u529b\u30d5\u30a1\u30a4\u30eb\u540d><\/p>\n<\/blockquote>\n\n\n\n
addm365user.ps1 \u3092\u5b9f\u884c\u3057\u307e\u3059\u3068\u3001\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b AddedNewUsers-YYYY_MM_DD-HH_MM.csv \u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3001\u65b0\u3057\u304f\u767b\u9332\u3055\u308c\u305f\u30e6\u30fc\u30b6\u30fc\u306e\u60c5\u5831\u304c\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n
\u3059\u3067\u306b\u767b\u9332\u6e08\u307f\u306e\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\u3059\u308b<\/strong><\/h2>\n\n\n\n\u3059\u3067\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u30ea\u30b9\u30c8\u306e\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8 (getm365user.ps1) \u3092\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\u3002
\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3068\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b RegisteredUsers-YYYY_MM_DD-HH_MM.csv \u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3001\u3059\u3067\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u304c\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n
\n###############################################################################################################################
# Name
# get365user.ps1 – Microsoft 365 \u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u53d6\u5f97\u3059\u308b
# SYNOPSIS
# getm3365user
# DESCRIPTION
# Microsoft 365 \u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\u3057\u3066\u3001RegisteredUsers_YYYY_MM_DD-HH_MM.csv \u306b\u51fa\u529b\u3057\u307e\u3059\u3002
###############################################################################################################################
Connect-MgGraph -Scopes “User.ReadWrite.All” > $null
Import-Module -Name Microsoft.Graph.Users
date
echo ” Get All users”
$addedtime = Get-Date -format “yyyy_MM_dd-HH_mm”
$outputfilename = “RegisteredUsers-” + $addedtime + “.csv”
Get-MgUser -All | Select-Object Id, UserPrincipalName, DisplayName, GivenName, Surname, JobTitle, EmployeeId, EmployeeType, Department, City, State, Country, StreetAddress, PostalCode | Export-Csv -Path $outputfilename -Encoding UTF8
date
echo ” Completed”<\/p>\n<\/blockquote>\n\n\n\n
\u30e6\u30fc\u30b6\u30fc\u3092\u524a\u9664\u3059\u308b<\/strong><\/h2>\n\n\n\n\u30e6\u30fc\u30b6\u30fc\u524a\u9664\u30ea\u30b9\u30c8\u306e\u4f5c\u6210<\/strong><\/p>\n\n\n\n\u524a\u9664\u3057\u305f\u3044\u30e6\u30fc\u30b6\u30fc\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u30021 \u884c\u76ee\u306b UserPrincipalName \u3068\u5165\u529b\u3057\u30012 \u884c\u76ee\u4ee5\u964d\u306b\u524a\u9664\u3057\u305f\u3044 UserPrincipalName \u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n