최신 정보
Office 365 관리 서비스 및 Exchange Online Services에 성공적으로 연결했습니다. Get-MsolUser와 같은 cmdlet을 테스트했으며 제대로 작동합니다. 그러나 Set-MsolUser 명령을 실행하여 Title을 변경하려고하면 아래와 같이 Access Denied 오류가 발생합니다. 수동으로 Exchange로 이동하여 원하는 속성을 변경할 수 있지만이 명령을 실행할 수 없기 때문에 이상합니다. 이 주위에 어떤 방법이 있습니까?
Office 365 사용자 특성을 업데이트하는 스크립트
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$savedcreds=$false ## false = manually enter creds, True = from file
$credpath = "c:\downloads\tenant.xml" ## local file with credentials if required
## If you have running scripts that don't have a certificate, run this command once to disable that level of security
## set-executionpolicy -executionpolicy bypass -scope currentuser -force
Clear-Host
write-host -foregroundcolor $systemmessagecolor "Script started`n"
#install-module msonline
Import-Module -Name "C:\Temp\MsOnline" -Verbose
write-host -foregroundcolor green "MSOnline module loaded"
## Get tenant login credentials
$cred = Get-Credential
## Connect to Office 365 admin service
connect-msolservice -credential $cred
write-host -foregroundcolor $systemmessagecolor "Now connected to Office 365 Admin service"
## Start Exchange Online session
$EXOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
import-PSSession $EXOSession -AllowClobber
write-host -foregroundcolor $processmessagecolor "Now connected to Exchange Online services`n"
write-host -foregroundcolor $systemmessagecolor "Script Completed`n"
# Load data from file.csv
$EXUsers = Import-csv file_path.csv
# Count variable for number of users update
$count = 0
# Go through each row that has user data in the CSV we just imported
ForEach($User in $EXUsers)
{
# Ppopulate hash table for Get-Msoluser splatting:
$GetParams =
@{
UserPrincipalName = $User.userPrincipalName
}
# Initialize hash table for Set-Msoluser splatting:
$SetParams =
@{
UserPrincipalName = $User.userPrincipalName
Title = $User.title
}
# Get user and update.
if ( Get-Msoluser @GetParams)
{
# Set User attributes
Set-MsolUser @SetParams
# Print that the user was updated
Write-Host -ForegroundColor Yellow "$User - User attributes have been updated."
# Update Count
$count += 1
}
}
# Print the number of updated users
Write-Host $count "Users have been updated" -ForegroundColor Green
에러 메시지:
Set-Msoluser : Access Denied. You do not have permissions to call this cmdlet.
At line:1 char:59
+ ... ncipalName "[email protected]" | Set-Msoluser -Title "Test Title"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.AccessDeniedException,Microsoft.Online.Administration.Automation.SetUser
해결
액세스 거부 문제는 Exchange 관리 셸 에서 스크립트를 실행하여 해결되었습니다.
또한 스크립트가 제대로 작동하도록 다음과 같이 변경되었습니다.
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
# Load data from file.csv
$EXUsers = Import-csv file_path.csv
# Count variable for number of users update
$count = 0
# Go through each row that has user data in the CSV we just imported
ForEach($User in $EXUsers)
{
# Ppopulate hash table for Get-Msoluser splatting:
$GetParams =
@{
Identity = $User.Identity
}
# Initialize hash table for Set-Msoluser splatting:
$SetParams =
@{
Identity = $User.Identity
Title = $User.Title
}
# Get user and update.
if ( Get-Mailbox @GetParams)
{
# Set User attributes
Set-User @SetParams
# Print that the user was updated
Write-Host -ForegroundColor Yellow "$User - User attributes have been updated."
# Update Count
$count += 1
}
}
# Print the number of updated users
Write-Host $count "Users have been updated" -ForegroundColor Green
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다