<# Test-In-For-loop.ps1 #> # Function to show the usage. function Show-Usage { $helpMessage = @" Usage: Test-In-For-looop.ps1 -f filename -q or -u [-c, -?]`n Mandatory parameter:`n -f filename filename is the csv file that contains the list of computers whose DNS IP or addresses need to be audited or updated.`n -i infile infile is the csv file that contains the list of computers with the DNS settings to be updated.`n -q or -u where -q will only audit the DNS servers or -u will update the DNS server settings.`n Optional parameter:`n -c computer computer is the name of the computer whose DNS IP addresses need to be audited or updated based on the -q or -u parameter above.`n -? Lists this help message. "@ $helpMessage exit; } foreach ($objUser In $unlicensedUserList) { if ($groupUserList.ContainsKey($objUser.UserPrincipalName)) { $userPrincipalName = $objUser.UserPrincipalName; $displayName = $groupUserList.Item($userPrincipalName); $msg = "Activating license for $displayName. . ."; try { Set-MsolUserLicense -UserPrincipalName $userPrincipalName -AddLicenses "domain:ENTERPRISEPACK"; $msg = "Activation completed successfully."; $object = '' | Select-Object 'User Name','Activated',Message; $object.'User Name' = $displayName; $object.'Activated' = $true; $object.Message = $msg; $activatedUserList += $object; } catch { $msg = $_.Exception.Message; $object = '' | Select-Object 'User Name','Activated',Message; $object.'User Name' = $displayName; $object.'Activated' = $false; $object.Message = $msg; $unActivatedUserList += $object; } } }