Thursday, 22 October 2015

Office 365 Users License Report with Powershell

We can find and list the applied license details of all the office 365 users by using the Azure AD powershell cmdlet Get-MsolUser. The Get-MsolUser cmdlet returns the user's license details along with other common user information.

Note: Before proceed, Install and Configure Azure AD PowerShell

Export Office 365 Users License Detail to CSV

The following powershell script gets the applied license detail for all the office 365 users by using Get-MsolUser cmdlet and it exports the output to csv file by using Export-CSV cmdlet.
$users = Get-MsolUser -All
$users | Foreach-Object{ 
  $licenseDetail = '' 
  $licenses='' 
  if($_.licenses -ne $null) {
ForEach ($license in $_.licenses){
  switch -wildcard ($($license.Accountskuid.tostring())) { 
           '*POWER_BI_STANDALONE' { $licName = 'POWER BI STANDALONE' } 
           '*CRMSTANDARD' { $licName = 'CRM Online' }
           '*O365_BUSINESS_PREMIUM' { $licName = 'Office 365 BUSINESS PREMIUM' } 
           '*ENTERPRISEPACK' { $licName = 'Office 365 (Plan E3)' }  
           default { $licName = $license.Accountskuid.tostring() }
        }         

  if($licenses){  $licenses = ($licenses + ',' + $licName) } else { $licenses = $licName}
ForEach ($row in $($license.servicestatus)) {

if($row.ProvisioningStatus -ne 'Disabled') {          
       switch -wildcard ($($row.ServicePlan.servicename)) { 
           'EXC*' { $thisLicence = 'Exchange Online' }  
           'LYN*' { $thisLicence = 'Skype for Business' } 
           'SHA*' { $thisLicence = 'Sharepoint Online' }       
           default { $thisLicence = $row.ServicePlan.servicename }  
       }         
 if($licenseDetail){ $licenseDetail = ($licenseDetail + ',' + $thisLicence) }  Else { $licenseDetail = $thisLicence}}
}}}
New-Object -TypeName PSObject -Property @{    
    UserName=$_.DisplayName  
    IsLicensed=$_.IsLicensed 
    Licenses=$licenses 
    LicenseDetails=$licenseDetail }
}  | Select UserName,IsLicensed,Licenses,LicenseDetails |
Export-CSV "C:\\Office-365-User-License-Report.csv" -NoTypeInformation -Encoding UTF8

Wednesday, 7 October 2015

How to make a Program run on Startup in Windows

Programs or shortcuts placed in the Startup folder will run automatically open whenever Windows starts. Follow the below steps to make a program run on windows startup.

1. Click the Start button and click Run...(or simply press Windows key + 'R').
2. Type the command "Shell:startup" in the Run dialog, and press Enter.

How to make a Program run on Startup in Windows
3. Now, you can see the Windows Startup folder.
4. Open the location that contains the item to which you want to create a shortcut.
5. Right-click the item, and then click Create Shortcut...
6. Copy the shortcut and Paste it into this Startup folder and Windows will automatically load them when you sign into your computer.

How to make a Program run on Startup in Windows

Tuesday, 6 October 2015

Convert Username to SID using VBScript

We can easily convert username to sid by using the WMI service class Win32_UserAccount with VBScript.

1. Copy the below example vb script code and paste it in notepad or a VBScript editor.
2. Save the file with a .vbs extension, for example: ConvertUsertoSID.vbs.
3. Double-click the vbscript file (or Run this file from command window).
4. Enter username and domain name and click Enter to resolve username to sid.
Option Explicit
Dim objWMIService,objAccount 
Dim strUserName,strSID,strDomainName,server

' Asks username and domain name from user.
strUserName = InputBox ("Please enter user name")
strDomainName = InputBox ("Please enter domain name")

  server = "."
  Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2") 
  Set objAccount = objWMIService.Get("Win32_UserAccount.Name='" & strUserName & "',Domain='" & strDomainName & "'")
  If Err.Number <> 0 Then
       Msgbox Err.Description
        Err.Clear
  Else
    Msgbox "User SID: " & vbtab & objAccount.SID & vbcrlf
  End If

Convert SID to Username using VBScript

We can easily convert object sid value to user friendly username by using the WMI service class Win32_SID with VBScript.

1. Copy the below example vb script code and paste it in notepad or a VBScript editor.
2. Save the file with a .vbs extension, for example: ConvertSIDtoUser.vbs.
3. Double-click the vbscript file (or Run this file from command window).
4. Enter the sid value that you want resolve as user name and click Enter.
Option Explicit
Dim objWMIService,objAccount 
Dim strUserName,strSID,strDomainName,server

' Asks object sid from user.
strSID = InputBox ("Please enter user sid value")
   If strSID = "" then
      Msgbox "No sid value entered"
   end if

  server = "."
  Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
  Set objAccount = objWMIService.Get("Win32_SID.SID='" & strSID & "'")
  strUserName = objAccount.AccountName
  strDomainName = objAccount.ReferencedDomainName
  If Err.Number <> 0 Then
       Msgbox Err.Description
        Err.Clear
  Else
 Msgbox "User name: " & vbtab & UCase(strUserName) & vbcrlf & "Domain name: " & vbtab & UCase(strDomainName)
  End If