Monday, November 28, 2022

New Active Directory user creation with email address information's for Office365 Sync. Assume you don't use inhouse exchange server

 

AD User adding script


Copy the text from here and save it to a file as NewADUser.ps1

#--------------------------------------------------------------------------------------

#This Script was Developed by Janaka (janakackv@gmail.com) 

#Script is designed to use in an environment that has AD-Sync configured with Office 365 tenant without having a Local exchange server. 

#By running the below script in PowerShell on your domain controller, Domain users can be created with add all the necessary attributes required to sync to the cloud. Then you can assign a license to your O365 Admin Centre.


#######Before your run######

#make sure to set your domain in $domain section.

#user has to input Username / SMTP ID / First name & last name etc. 


#######After the script######

#New users will be created in Default Users OU. You can move new ADUser to target OU which has been configured to Sync with O365 Tennant. 


#Define variables;

$domain = "YOU DOMAIN"

$username = Read-Host -Prompt 'Type User name(all small letters)'

$email = Read-Host -Prompt 'Input External Email Address(all small letters)'

$fname = Read-Host -Prompt 'Input First Name(First Letter CAPS)'

$lname = Read-Host -Prompt 'Input Last Name(First Letter CAPS)'

$dept = Read-Host -Prompt 'Input Department(ALL CAPS)'

$comp = Read-Host -Prompt 'Input Company(Follow standard)'


#Creating ADUser by using the above variables 

Get-Module -name ActiveDirectory

New-ADUser -sAMAccountName "$username" -name "$fname $lname" -GivenName $fname -Surname $lname -displayName "$fname $lname" -Accountpassword (Read-Host -AsSecureString "AccountPassword") -Enabled $true -OtherAttributes @{'mailNickname'="$fname";'mail'="$email";'userPrincipalName'="$username@$domain";'proxyAddresses'="SMTP:$email";'company'="$comp";'department'="$dept"}

Start-Sleep -Seconds 2


#Get User information 

Get-ADUser "$username" -Properties CanonicalName, Enabled, GivenName, Surname, Name, UserPrincipalName, samAccountName, whenCreated, PasswordLastSet  | Select CanonicalName, Enabled, GivenName, Surname, Name, UserPrincipalName, samAccountName, whenCreated, PasswordLastSet


####END OF SCRIPT####


Wednesday, September 28, 2022

Rename a domain computer remotely via PowerShell Script

Rename a domain computer via PowerShell using below commands:

Frst Change the domain credentials here with your domain

$cred = Get-Credential intercol\administrator

Rename-Computer -ComputerName "OLDNAME" -NewName "NEW-NAME" -LocalCredential intercol\administrator -DomainCredential $cred -Force -PassThru -Restart

PowerShell Script to Disable mailbox and enable as remote mailbox user for Office365 migration

 

Copy the below Script into PowerShell script file and then run it in exchange PowerShell. before running change YourO365TenanetID and YourMailDomain sections with relevant information.

#---------------------------

$username = Read-Host -Prompt 'Type User name'

$email = Read-Host -Prompt 'Input SMTP ID'

$Date = Get-Date

Get-Mailbox -Identity $username | fl Email*


$confirmation = Read-Host "Do you need to disable user '$username' Mailbox before migration? [Y/N]"

if ($confirmation -eq 'y') {

   Disable-Mailbox -Identity "$username"

   }

Start-Sleep -Seconds 5

Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq “Disabled” } | ft

Start-Sleep -Seconds 4


$confirmation2 = Read-Host "Do you need to enable remote mailbox for '$username' ? [Y/N]"

if ($confirmation2 -eq 'y') {

   Enable-RemoteMailbox $username -RemoteRoutingAddress $username@YourO365TenanetID -PrimarySmtpAddress $email@YourMailDomain

   }

Start-Sleep -Seconds 5

    Get-RemoteMailbox -Identity $username | fl Email*

Start-Sleep -Seconds 2

    Set-RemoteMailbox "$username" -EmailAddressPolicyEnabled $true

    Set-RemoteMailbox "$username" -EmailAddressPolicyEnabled $false  

    Set-RemoteMailbox "$username" -RemoteRoutingAddress $username@YourO365TenanetID -PrimarySmtpAddress $email@YourMailDomain

#---------------------------------------

Get In-Place Archive status and export In-Plce archive mailbox to a path

Get USers who have in-place archive Online archive is enabled

Get-Mailbox "username" | Format-List *Archive*


Convert in-plce archve to PST

New-MailboxExportRequest -Mailbox Username -FilePath "\\192.168.10.14\PST\user_Archive.pst" -IsArchive



Get Disconnected or Disabled mailboxes in Exchange server using PowerShell in all the databases

Get Disconnected or Disabled mailboxes in Exchange server using PowerShell in all the databases 


Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq “Disabled” } | ft DisplayName,Database,DisconnectDate