Remove all license user without one user as global admin

Hi, I would like to remove all license user without global admin, this account needs to deactivate domain connection. And if we remove office 365 license users, it moves to recyle bin as soft delete,  in this case if we need to recover it, it is so easy and usefulness, but after 30 days, we cannot restore their users anymore. Sometimes we want to remove users without storing recycle bin about 30 days,  to execute this command we need to declare

  1. Get all licesne users without one specific user then export to csv file.
  2. Store user’s userprincipalName using Import-Csv with specific csv file.
  3. In the for loop statement, Remove-MsolUser with reference userprincipalName which we’ve gotten already to set, with -force option
  4. Repeat all statements in the for-loop statements
  5. Get all users from recyle-bin , which are already removed as soft-delete , then remove-msolUser from RecyleBin with -RemoveFromRecyleBin and -Force option

To use on this declarations, we can make powershell document

Get-MsolUser | Where-Object {$_.isLicensed -eq “TRUE” -and $_.UserPrincipalName -ne “UserPrincipalNameEmail”} | Export-csv d:\cloudwide1602Users.csv
$users = Import-csv d:\cloudwide1602Users.csv
foreach ($user in $users){
    Remove-MsolUser -UserPrincipalName $user.UserPrincipalName -Force
}

Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force

To execute this cmdlet, then if I move to deleted users page on office 365 portal, there is no deleted users to recover.

Advertisements

글쓴이: hongwoo jin

I'm managing our Korea company's Office 365 administrator I want to be MS Office 365 & SharePoint MVP with certification.

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

Google+ photo

Google+의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

%s에 연결하는 중