Archive

Posts Tagged ‘Powershell’

Export Mailbox into a PST from Exchange 2010

March 15, 2017 Leave a comment

Below are the commands required to export mailbox and save in PST format.

# Give permissions to user doing the export

New-ManagementRoleAssignment –Role "Mailbox Import Export" –User Admin

# Create Network Share and give permissions to Exchange Trusted Subsystem read/write

# Start the Mailbox Export

New-MailboxExportRequest -Mailbox first.surname -FilePath \\comp\share

# Start mailbox export with archive

New-MailboxExportRequest -Mailbox first.surname -FilePath \\comp\share -IsArchive

# Check the status of mailbox export request

Get-MailboxExportRequest 

or

Get-MailboxExportRequest | Get-MailboxExportRequestStatistics

# When Mailbox export request has been finished. Remove it

Get-MailboxExportRequest | Where {$_.status -eq "Completed"} | Remove-MailboxExportRequest

-Eric

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

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

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

PowerShell – Azure AD Connect sync: Scheduler Command Cheat Sheet

May 13, 2016 Leave a comment

Here are some of the commands.

To view the Scheduler configuration:

Get-ADSyncScheduler

This shows you the current sync configuration information like interval, sync policy type, next sync cycle start time etc.

To change the scheduler configuration:

Set-ADSyncScheduler

This allows you to change some the following sync parameters.

  • CustomizedSyncCycleInterval
  • NextSyncCyclePolicyType
  • PurgeRunHistoryInterval
  • SyncCycleEnabled
  • MaintenanceEnabled

To Start the Scheduler manually:

There are two synchronization options – Delta and Full.
Delta – Use this when there is an urgent change that needs to be synchronized immediately.

Start-ADSyncSyncCycle -PolicyType Delta

Full – Use this when the following changes have been made.

  • Synchronization rules have been changed
  • Filtering changes, which included different number of objects
  • More attributes or objects are to be imported from source directory
    Start-ADSyncSyncCycle -PolicyType Initial
    Check the status of the connector:
    Get-ADSyncConnectorRunStatus

    If its busy and running the sync the connector name will be returned.

 

More info – Azure Documentation

-Eric

How to clear values via PowerShell in Active Directory

March 23, 2016 Leave a comment

Command:

$user = domainuser

set-aduser $user –clear manager

This also works for multiple values, like phonenumber, address etc. just add a coma after values.

-Eric