Friday, 23 December 2016

Create User And Assign Licenses In O365 Using PowerShell Script

Create User And Assign Licenses In O365 Using PowerShell Script

Pre-Requisites:
      1)      Office 365 account (work or personal account).

      2)      There are 2 binaries that you need to install: -
·         Microsoft Online Services Sign-In Assistant for IT Professionals RTW

·         Azure Active Directory Module for Windows PowerShell

Both of these need to be the 64bit version to work together.

Connect to O365

1.      On your local computer, open Windows PowerShell as an administrator (use Run as administrator).

 Run this command, and enter your Office 365 work or school account credentials.
$Credential = Get-Credential

               In the Windows PowerShell Credential Request dialog box, type your Office                                    365 username and password, and then click OK.


2.    To view login credentials, run the following command –
       $credential

  The command returns data similar to this:

UserName                                                   Password
--------                                                   --------
yourname@companyname.onmicrosoft.com System.Security.SecureString
 
 
3.    Import MSOnline module to allow connectivity to Microsoft Office 365 
Import-Module MsOnline
 
4.    Establish a PS session with Microsoft Office 365
 
Connect-MsolService -Credential $credential
 
5.      Run the following command: -

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $credential -Authentication Basic AllowRedirection

$importresults = Import-PSSession $s


6.      To view summary information about your current licensing plans and the available licenses for each plan, run the following command:

Get-MsolAccountSku
           
   The command returns data similar to this:

AccountSkuId             ActiveUnits WarningUnits ConsumedUnits
------------             ----------- ------------ -------------
companyname:ENTERPRISEPACK 0           25           6           
companyname:CRMSTANDARD    0           25           1           


        The results contain the following information:

·        AccountSkuId
Show the available licensing plans for your organization by using the syntax <CompanyName>:<LicensingPlan>. <CompanyName> is the value that you provided when you enrolled in Office 365, and is unique for your organization. The <LicensingPlan> value is the same for everyone. For example, in the value litwareinc:ENTERPRISEPACK, the company name is litwareinc, and the licensing plan name ENTERPRISEPACK, which is the system name for Office 365 Enterprise E3.

·        ActiveUnits
Number of licenses that you've purchases for a specific licensing plan.

·        WarningUnits
Number of licenses in a licensing plan that you haven't renewed, and that will expire after the 30-day grace period.

·        ConsumedUnits
Number of licenses that you've assigned to users from a specific licensing plan.


7.      To view the list of all user accounts and their licensing status, run the following command:

Get-MsolUser -All
Or
Get-MsolUser

                In turn, Get-MsolUser returns data similar to this:
           
UserPrincipalName                            DisplayName      isLicensed
-----------------                              -----------      ----------
pallavias@companyname.onmicrosoft.com          Pallavi AS       True     
zia@companyname.onmicrosoft.com                Zia Siddiqui     True     
jyotishah@companyname.onmicrosoft.com          Jyoti Shah       True     
sonaliwetal@companyname.onmicrosoft.com        Sonali Wetal     True     
manjarinagle@companyname.onmicrosoft.com       Manjari Nagle    True     
parikshitanagle123@companyname.onmicrosoft.com parikshita nagle True     



To view the list of all unlicensed user accounts in your organization, run the following command:

Get-MsolUser -All -UnlicensedUsersOnly

This command returns information about any users who are not currently licensed for Office 365:

               UserPrincipalName           DisplayName                     isLicensed
-----------------           -----------                     ----------
            BelindaN@litwareinc.com     Belinda Newman                  False

To view the list of all licensed user accounts in your organization, run the following command:

Get-MsolUser -All | where {$_.isLicensed -eq $true}

The command returns data similar to this:

UserPrincipalName                            DisplayName      isLicensed
-----------------                            -----------      ----------
pallavias@companyname.onmicrosoft.com          Pallavi AS       True      
zia@companyname.onmicrosoft.com                Zia Siddiqui     True     
jyotishah@companyname.onmicrosoft.com          Jyoti Shah       True     
sonaliwetal@companyname.onmicrosoft.com        Sonali Wetal     True     
manjarinagle@companyname.onmicrosoft.com       Manjari Nagle    True     
parikshitanagle123@companyname.onmicrosoft.com parikshita nagle True     



8.      To create an individual account, use the following syntax :

New-MsolUser -DisplayName <DisplayName> -FirstName <FirstName> -LastName <LastName> -UserPrincipalName <Account> -UsageLocation <CountryCode> -LicenseAssignment <AccountSkuID> [-Password <Password>]
This example creates an account for the United States user named User 1, and assigns a license from the companyname:ENTERPRISEPACK (Office 365 Enterprise E3) licensing plan :-

New-MsolUser -DisplayName "User 1" -FirstName User -LastName 1 -UserPrincipalName user1@ companyname.onmicrosoft.com -UsageLocation US -LicenseAssignment companyname:ENTERPRISEPACK

In turn, this returns data similar to this:

Password UserPrincipalName               DisplayName isLicensed
-------- -----------------               ----------- ----------
Cunu9586 user1@companyname.onmicrosoft.com  user1    True     


To verify that the user has been assigned a license, run a command like the following:

Get-MsolUser -UserPrincipalName
"user1@yourcompany.onmicrosoft.com"

If everything worked as expected, you should see that Varun’s isLicensed property is now set to True:

UserPrincipalName                       DisplayName isLicensed
-----------------                       ----------- ----------
User1@companyname.onmicrosoft.com       User 1        True  


            Now, set password for the user account. Run the following command: -

    Set-MsolUserPassword -UserPrincipalName                                     user1@companyname.onmicrosoft.com -NewPassword                   YourPassword -ForceChangePassword $False
or
             Set-MsolUserPassword -UserPrincipalName                                              yourname@companyname.onmicrosoft.com -NewPassword                    YourPassword -ForceChangePassword $True

9.      This example shows the services that user user1@companyname.onmicrosoft.com has access to. This shows the services that are associated with all licenses that are assigned to his account.
 
(Get-MsolUser -UserPrincipalName 
user1@companyname.onmicrosoft.com).Licenses.ServiceStatus

In turn, this returns data similar to this:
 
ServicePlan           ProvisioningStatus
-----------           ------------------
FLOW_O365_P2          Success          
POWERAPPS_O365_P2     Success          
TEAMS1                Success          
PROJECTWORKMANAGEMENT Success          
SWAY                  Success           
INTUNE_O365           PendingActivation
YAMMER_ENTERPRISE     Success          
RMS_S_ENTERPRISE      Success          
OFFICESUBSCRIPTION    Success          
MCOSTANDARD           Success          
SHAREPOINTWAC         Success          
SHAREPOINTENTERPRISE  Success          
EXCHANGE_S_ENTERPRISE Success     


Testing

Login to the O365 portal (portal.office.com) using the credentials: -

Password: **********

Perform few operations like: -

·         Sending email
·         Go to admin portal
·         Check users
·         Check newly added users
·         Check licenses, etc.


Script

$credential = Get-Credential

Import-Module MsOnline

$credential

Connect-MsolService -Credential $credential

Get-MsolAccountSku

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $credential
-Authentication Basic -AllowRedirection

$importresults = Import-PSSession $s

Get-MsolUser

(Get-MsolUser -UserPrincipalName youname@companyname.onmicrosoft.com).Licenses.ServiceStatus

Get-MsolUser | where {$_.isLicensed -eq $true}

Get-MsolUser -All -UnlicensedUsersOnly

New-MsolUser -DisplayName "Firstname Lastname" -FirstName Yourfirstname -LastName Yourlastname -UserPrincipalName youname@companyname.onmicrosoft.com
-UsageLocation US -LicenseAssignment companyname:O365_BUSINESS_PREMIUM

Set-MsolUserPassword -UserPrincipalName youname@companyname.onmicrosoft.com -NewPassword YourPassword -ForceChangePassword $False




Thursday, 22 December 2016

Prepare/Generalize an Ubuntu Virtual Machine for Azure


Prerequisites

Install an Ubuntu Linux operating system to a virtual hard disk.

Ubuntu installation notes:
  • The VHDX format is not supported in Azure, only fixed VHD. You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
  • When installing the Linux system, it is recommended that you use standard partitions rather than LVM (often the default for many installations). This will avoid LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another VM for troubleshooting. LVM or RAID may be used on data disks if preferred.
  • Do not configure a swap partition on the OS disk. The Linux agent can be configured to create a swap file on the temporary resource disk. More information about this can be found in the steps below.
  • All of the VHDs must have sizes that are multiples of 1 MB.
STEPS:
1.       In the center pane of Hyper-V Manager, select the virtual machine.
2.      Click Connect to open the window for the virtual machine.
3.      Replace the current repositories in the image to use Ubuntu's Azure repos. The steps vary slightly depending on the Ubuntu version.
  
 Before editing /etc/apt/sources.list, it is recommended to make a backup:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak


  #sudo sed -i "s/[a-z][a-z].archive.ubuntu.com/azure.archive.ubuntu.com/g" /etc/apt  /sources.list

         sudo apt-get update


4.      Update the operating system to the latest kernel by running the following commands:

# sudo apt-get update


# sudo apt-get install linux-image-virtual


 (recommended) sudo apt-get dist-upgrade



       Once all the above necessary packages were install, make sure to reboot your Linux box

 # sudo reboot

5.      Modify the kernel boot line for Grub to include additional kernel parameters for Azure. To do this open "/etc/default/grub" in a text editor, find the variable called GRUB_CMDLINE_LINUX_DEFAULT (or add it if needed) and edit it to include the following parameters:

                  GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0,115200n8                                 earlyprintk=ttyS0,115200 rootdelay=300"


Save and close this file, and then run 'sudo update-grub'. This will ensure all console messages are sent to the first serial port, which can assist Azure technical support with debugging issues.

#sudo update-grub

6.      Ensure that the SSH server is installed and configured to start at boot time. This is usually the default. 

7.      Install the Azure Linux Agent:

        # sudo apt-get update
        # sudo apt-get install walinuxagent


Note: Installing the walinuxagent package will remove the NetworkManager and NetworkManager-gnome packages, if they are installed.

8.      The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. Note that the local resource disk is a temporary-disk, and might be emptied when the VM is deprovisioned.

After installing the Azure Linux Agent (see previous step), modify the following parameters in /etc/waagent.conf appropriately:

          #vi /etc/waagent.conf


      ResourceDisk.Format=y
      ResourceDisk.Filesystem=ext4
      ResourceDisk.MountPoint=/mnt/resource
      ResourceDisk.EnableSwap=y
      ResourceDisk.SwapSizeMB=2048    


## NOTE: set this to whatever values you need it to be.

9.      Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:

sudo waagent -force -deprovision
export HISTSIZE=0
logout / exit



10. Click Action -> Shut Down in Hyper-V Manager. Your Linux VHD is now ready to be uploaded to Azure.

You're now ready to use your Ubuntu Linux virtual hard disk to create new virtual machines in Azure.

Get SSL Certificate Expiry Notification on Mail.

 There are multiple ways to get SSL Certification expiry details/alert. We all know if our SSL certificate get expire, how critical situatio...