Archive

Archive for May, 2016

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 recover sysadmin access to SQL Server 2005/2008 R2 when sa password is lost

May 9, 2016 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 “Advanced” tab, and in the Properties text box add “;–m” to the end of the list in the “Startup parameters” option

    Note! – Please make sure there is no space between “;” and “-m”. In the SQL Server ERRORLOG, there should be an entry that says   “SQL Server started in single-user mode.”

  5. Click the “OK” button and restart the SQL Server Instance

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 SERVER1\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 “;-m” from the startup parameters using the Configuration Manager and restart the SQL Server Instance

-Eric