PowerShell Commands for a O365 System Admin

Create New O365 User

Connect-MsolService‚Äč

New-Msoluser -UserPrincipalName torky.elenazy@alamarfoods.com -DisplayName "Torky ElEnazy" -FirstName Torky -LastName Elenazy -Country SA -MobilePhone +966594399666 -Fax SADP01334 -Department "Human Resources" -Title "Recruiter Assistant" -UsageLocation SA

Adding License to user

Set-MsolUserLicense -AddLicenses AlamarFoods:O365_BUSINESS_PREMIUM -UserPrincipalName mohammed.hemdan@alamarfoods.com

Add Manager Credentials – first connect to Exchange Online

Add Manager – MFA Enabled

Connect to EAC<Hybrid<Exchange Online Powershell with MFA

Connect-EXOPSSession -UserPrincipalName shrenik.salguna@alamarfoods.com

(in Hybrid PowerShell )

Set-User -Identity mohammed.hemdan@alamarfoods.com -Manager mohammed.roustom@alamarfoods.com

Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Add to Distribution List – (Office365 Groups)

Add-DistributionGroupMember -Identity "Alamar Foods" -Member "kiran.venugopal@alamarfoods.com"

Add-DistributionGroupMember -Identity "Alamar Corporate" -Member "kiran.venugopal@alamarfoods.com"

Add to O365 Group

Add-UnifiedGroupLinks -Identity "Alamar Foods KSA" -LinkType Members -Links kiran.venugopal@alamarfoods.com

Create New User in Active Directory

New-ADUser -Name "Kiran Venugopal" -GivenName "Kiran" -Surname "Venugopal" -SamAccountName "kiran.venugopal" -UserPrincipalName "kiran.venugopal@alamarfoods.com" -Office "Head Office" -EmailAddress "kiran.venugopal@alamarfoods.com" -Mobile "+971551477891" -Title "KSA Financial Analyst" -Department "Finance" -Path "OU=Finance,OU=HO Users,OU=Saudi Arabia-HO,DC=alamarfoods,DC=local" -AccountPassword(Read-Host -AsSecureString "Aa123456") -Company "Alamar Foods | KSA" -City "Riyadh" -Country ‘SA’ -StreetAddress "AlOlaya District, Street No. 36, Building No. 3" -POBox ‘4748’ -Manager "usama.ruby" -Enabled $true

For MENAP Users

New-ADUser -Name "Mohamed Younes" -GivenName "Mohamed" -Surname "Younes" -SamAccountName "mohamed.younes" -UserPrincipalName "mohamed.younes@alamarfoods.com" -Office "Head Office" -EmailAddress "mohamed.younes@alamarfoods.com" -Mobile "+20106644628" -Title "Warehouse Supervisor" -Department "Supply Chain" -Path "OU=Commissary,OU=EG Users,OU=Egypt,OU=MENAP,DC=alamarfoods,DC=local" -AccountPassword(Read-Host -AsSecureString "Aa123456") -Company "Alamar Foods | Egypt" -City "Cairo" -Country ‘EG’ -Manager "mohamed.amer" -Enabled $true

Adding Manager thru CSV command

Create CSV; UserPrincipalName; (see desktop)

Manager

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Add Manager

Set-User -Identity mohammed.hemdan@alamarfoods.com -Manager mohammed.roustom@alamarfoods.com

Import-Csv "C:\Users\shrenik.salguna\Desktop\UpdateManager.csv" | foreach {Set-User -Identity $_.UserPrincipalName -Manager $_.Manager}

Get all properties of user

Get-User | gm

Get properties of user and manager

Get-User | select -Property Name,Manager

Export to CSV

Get-User | select -Property Name,Manager | Export-csv "C:\Users\shrenik.salguna\Desktop\Manager.csv"

"C:\Users\shrenik.salguna\Desktop\UpdateManager.csv" | foreach {Set-User -Identity $_.UserPrincipalName -Manager $_.Manager}