Archive

Archive for the ‘Commands’ Category

Manage Office 365 User licenses with Powershell

January 13, 2017 Leave a comment

Install required Software first

  • Install the 64-bit version of the Microsoft Online Services Sign-In Assistant – LINK
  • Install the 64-bit version of the Windows Azure Active Directory Module for Windows PoweShell – LINK

PowerShell commands

# Import MSOnline Module

Import-Module MSOnline

# Connect to Office 365

$O365Cred = Get-Credential
Connect-MsolService -Credential $O365Cred

# Show Licenses

Get-MsolAccountSku

# View details about the Services that are available in all of your license plans

Get-MsolAccountSku | Select -ExpandProperty ServiceStatus

# Check which users have licenses

Get-MsolUser -All | fl DisplayName, UsageLocation,isLicensed,Licenses

# Check if a user has a license – Single

Get-MsolUser -UserPrincipalName "user.name@domain.com" | ft DisplayName, UsageLocation,isLicensed,Licenses

# Add a license – Single user

Set-MsolUserLicense -UserPrincipalName "user.name@domain.com" -AddLicenses "company:ENTERPRISEPACK"

# Remove a license – Single user

Set-MsolUserLicense -UserPrincipalName "user.name@domain.com" –RemoveLicenses "company:ENTERPRISEPACK"

# Bulk Add licenses

$Users = Import-Csv -Path "C:\Temp\licenses.csv"
foreach ($User in $Users)
{
    $UPN = $User.‘SamAccountName’ + "@zhgplc.com"
    Set-MsolUser -UserPrincipalName "$UPN" -UsageLocation "GB"
    Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "company:ENTERPRISEPACK"
}

# Bulk check added licenses 

$Users = Import-Csv -Path "C:\Temp\licenses.csv"
foreach ($User in $Users)

{
    $UPN = $User.‘SamAccountName’ + "@zhgplc.com"
    Get-MsolUser -UserPrincipalName "$UPN" | ft DisplayName, UsageLocation, Licenses
}

 

-Eric

How to recover sysadmin access to SQL Server 2012 when sa password is lost

January 12, 2017 Leave a comment
  1. Open the SQL Server Configuration Manager tool
  2. Navigate to SQL Server Services and Stop the SQL Server Instance that needs a sa password reset
  3. Right click the on the instance/service and select properties.
  4. Go to the “Startup Parameters” tab, and in the Specify a Startup Parameter text box write  “-mSQLCMD”, click Add and then click OK.
  5. Restart the SQL Server Instance  which will now be running in single-user mode

When the SQL Server Instance starts in single-user mode,  you can use the Windows Administrator account to connect to SQL Server using the sqlcmd utility and Windows authentication.

Connect to SQL Server using sqlcmd: sqlcmd –S.\SQLExpress

The following example adds the account “John” in the “EXAMPLE” domain to the SQL Server “sysadmin” role:

EXEC sp_addsrvrolemember ‘EXAMPLE\John, ‘sysadmin’;
GO

Note!
Once the sysadmin access has been recovered, remove the “;-mSQLCMD” from the startup parameters using the Configuration Manager and restart the SQL Server Instance

-Eric

Categories: Commands, Microsoft, SQL Tags: ,

Can’t import Windows 10 Pro WIM into MDT 2013 Update 2

January 9, 2017 Leave a comment

Here are the steps:

  • Download Microsoft Media Creation Tool.
  • Start the tool and select the option to create ISO files to install on another computer.
  • Once all is downloaded and the Tool allows you to press finish – DON’T
  • Check C:\ESD folder for files (as it should contain installx86.esd and installx64.esd)
  • Copy ESD folder to C:\TEMP
  • Convert the esd files to wim using the following command: dism /export-image /sourceimagefile:C:\$Windows.~WS\Sources\installx64.esd /SourceIndex:4
    /destinationimagefile:C:\install.wim /destinationname:"Windows 10 Pro x64" /compress:max /checkintegrity
  • Import the new WIM files to MDT 2013 Update 2

-Eric

PowerShell – Search any User on Active Directory–updated

November 21, 2016 Leave a comment

Below is an updated script that helps you find any user in AD with details like when the User object was created, modified, lockout time, bad password time, last logon etc.

$user = Read-Host "Enter the name of the user"
Get-ADUser -Filter "sAMAccountName -like ‘*$user*’" |
Get-ADObject -Properties * | fl Name,SamAccountName,UserPrincipalName,DistinguishedName,objectSID,Title,Department,telephoneNumber,` Created,Modified,lockoutTime,`
@{n=’accountExpires’;e={[DateTime]::FromFileTime($_.accountExpires)}},`
@{n=’LastLogon’;e={[DateTime]::FromFileTime($_.LastLogon)}},`
@{n=’badPasswordTime’;e={[DateTime]::FromFileTime($_.badPasswordTime)}},`
@{n=’pwdLastSet’;e={[DateTime]::FromFileTime($_.pwdLastSet)}},`
msExchWhenMailboxCreated

-Eric

VMware – Commands to power on VMs from command line

November 10, 2016 Leave a comment

ESXi 5.x and 6.0

List the inventory ID of the virtual machine with the command:

vim-cmd vmsvc/getallvms | grep <vm name>

Note: The first column of the output shows the vmid.

Check the power state of the virtual machine with the command:

vim-cmd vmsvc/power.getstate <vmid>

Power-on the virtual machine with the command:

vim-cmd vmsvc/power.on <vmid>

ESX 4.0 and ESX 4.1

To list the path of all the virtual machines on the host:

vmware-cmd –l

Get the state of the virtual machine with the command:

vmware-cmd <path to the VMX file> getstate

Power on the virtual machine with the command:

vmware-cmd <path to the VMX file> start
    
-Eric

PowerShell – Search any User on Active Directory

May 24, 2016 Leave a comment

Below is a small PowerShell script that allows you to search any user on Active Directory:

$user = Read-Host "Enter the name of the user"
Get-ADUser -Filter "sAMAccountName -like ‘*$user*’" |
Get-ADObject -Properties * | ft Name,SamAccountName,Title,,UserPrincipalName,Department

-Eric

PowerShell – Search and Unlock Active Directory Account

May 23, 2016 Leave a comment

Nice little one-liner to Find and Unlock Active Directory Accounts

Search-ADAccount -LockedOut | Unlock-ADAccount –Confirm

-Eric