none
enable logging for the O365 license management script RRS feed

  • General discussion

  • I am new to powershell and my boss asked me to create high level logging for the O365 license assignment script.

    Could any one please help me on how to enable logging to find out the E3 license and sub licenses are correctly assigned to user or not. If not, what is the issue.

    import-module msonline
    #$pwd = Mouse E:\O365Scripts\Data\DONOTDELETE_SecureString.txt | convertto-securestring
    #$msolcred = new-object -typename System.Management.Automation.PSCredential -argumentlist "ralf@xx.onmicrosoft.com",$pwd
    #$MSolCred = new-object -typename System.Management.Automation.PSCredential -argumentlist "ralf@xx.onmicrosoft.com.onmicrosoft.com",$pwd
     
    #$MSolCred = Get-Credential
    #Connect-MsolService -Credential $MSolCred
    #Get-MsolAccountSku
     
    #Initiate variables for Active Directory query
    $D =[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    $Domain = [ADSI]"LDAP://$D"
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher
    $Searcher.PageSize = 200
    $Searcher.SearchScope = "subtree"
     
    #Get the Enterprise Pack Account SKU ID
    $AcctSKU = (Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq"E3"}).AccountSkuId
     
    # Breakdown of "Service Plan" in the E3 (licenses):
    # -- OFFICESUBSCRIPTION – Office Professional Plus
    # -- MCOSTANDARD – Lync Online
    # -- SHAREPOINTWAC – Microsoft Office Web Apps
    # -- SHAREPOINTENTERPRISE – SharePoint Online
    # -- EXCHANGE_S_ENTERPRISE – Exchange Online
    # Set options for which services to DISABLE
    $options = New-MsolLicenseOptions -AccountSkuID $AcctSKU `
      -DisabledPlans MCOSTANDARD,YAMMER_ENTERPRISE
    # -DisabledPlans MCOSTANDARD,SHAREPOINTWAC,SHAREPOINTENTERPRISE,EXCHANGE_S_ENTERPRISE
     
    $UnlicensedUsers = Get-MSOLUser -UnlicensedUsersOnly -All
    foreach ($user in $UnlicensedUsers){
      $upn = $user.UserPrincipalName
      $Searcher.Filter = "(&(objectCategory=person)(objectClass=user)(userprincipalname=$upn))"
      $Results = $Searcher.FindAll()
      forEach($Result in $Results){
      $ResourceType = $Result.Properties.Item("msExchResourceMetaData")
      $UAC = $Result.Properties.Item("userAccountControl")
      $IsDisabled = $Result.GetDirectoryEntry().InvokeGet('AccountDisabled')
      $cc = $Result.Properties.Item("c")
      If(([string]::IsNullOrEmpty($ResourceType)) -and (!$IsDisabled)){
      write-host $upn `t $ResourceType `t $UAC `t $IsDisabled `t $cc
      #Set COUNTRY CODE value in O365 for this user
      write-host "$upn : Found country code: $cc - Setting UsageLocation in O365"
      Set-MSOLUser -userprincipalname $upn -UsageLocation $cc
     
      ##############################
      #NOTE: We must to assign the user to the E3 license pack first
      # and then disable the licenses we don't want them to have
      ##############################
     
      #Enable the O365 E3 license for this user
      write-host "$upn : Assigning this user to use the E3 license"
      Set-MSOLUserLicense -UserPrincipalName $upn -AddLicenses $AcctSKU
     
      #Set license options to disable unwanted license assignments
      write-host "$upn : Licensing this user for OFFICESUBSCRIPTION only"
      Set-MsolUserLicense -UserPrincipalName $upn -LicenseOptions $options
    }
    }
    }


    chandradeep

    • Changed type Bill_Stewart Friday, July 27, 2018 6:28 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 6:29 PM This is not "debug/fix/rewrite my script for me" forum
    Tuesday, May 1, 2018 2:19 PM

All replies