Disable PowerShell for users in Exchange

The script checks whether users have 1 of these 3 roles in Office 365: Company Administrator SharePoint Service Administrator Exchange Service Administrator After that, all users are retrieved and then checked for each user if they have an admin role, if not PowerShell disabl

 
 
 
 
 
(0)
414 times
Add to favorites
Office 365
2/8/2019
E-mail Twitter del.icio.us Digg Facebook
  • Typos in Script
    1 Posts | Last post November 20, 2019
    • I'm not sure if you checked but there are several typos in the script. I managed to get it to run using the below (i commented out the line to disable powershell as i just wanted to test it out):
      
      $roles = "Company Administrator", "SharePoint Service Administrator", "Exchange Service Administrator"
      
      $data = @()
      
      foreach ($role in $roles)
      
      {
      
      $r=Get-MsolRole -RoleName $role
      
      write-output $role
      
      $users=Get-MsolRoleMember -RoleObjectId $r.objectid
      
      $data+=$users
      
      }
      
      $users = Get-MsolUser -All
      
      foreach ($u in $users)
      
      {
      
      if(!($data.emailaddress -contains $u.UserPrincipalName))
      
      {
      
      write-output $u.UserPrincipalName
      
      #Set-user-identity $u.UserPrincipalName-RemotePowerShellEnabled $false
      
      }
      
      else
      
      {
      
      Write-host "USER IS IN DATA"-BackgroundColor Red
      
      }
      
      }