none
working on a script to automate assigning license to all office 365 unlicensed users RRS feed

  • Question

  • i have worked on some scripts that assign licenses to all unlicensed users, the challenge here is that i will prompt for the tenant admin credentials, my goal is to schedule this script to run daily so i can have this task automated, so is there a way to embed the creds in the script so it doesn't ask for creds?

    this is the one i am using

    Connect-MSOLService -Credential $adminCredential
    $AccountSkuId = "linces name"
    $UsageLocation = "us"

    $LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId

    $Users = Get-MSOLUser -All -UnlicensedUsersOnly

    $Users | ForEach-Object {

                  Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation

                  Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuId -LicenseOptions $LicenseOptions

    Tuesday, March 22, 2016 8:05 AM

Answers