Skip to content

Instantly share code, notes, and snippets.

@manickamk
Last active December 4, 2019 01:26
Show Gist options
  • Save manickamk/284d9b3d0c7f9264acd2e7945553359c to your computer and use it in GitHub Desktop.
Save manickamk/284d9b3d0c7f9264acd2e7945553359c to your computer and use it in GitHub Desktop.
Connect-MsolService
##############################################################
Get LastPasswordChangeTimestamp for all the users:
Get-MsolUser -All| select UserPrincipalName, LastPasswordChangeTimestamp|Export-Csv D:\user.csv
#####################################################################
Bulk reset Password and ForceChangePassword:
Import-Csv C:\users.csv | ForEach-Object { Set-MsolUserPassword -UserPrincipalName $_.UserPrincipalName -NewPassword $_.Newpassword -ForceChangePassword $true}
#####################################################################
Password Enforce
Import-Csv D:\o365\PassowrdChange\users.csv | ForEach-Object{Set-MsolUserPassword -UserPrincipalName $_.UserPrincipalName -ForceChangePasswordOnly $true -ForceChangePassword $true}
Template -------UserPrincipalName--------------
##########################################################################
Run the following command to set the password of one user to never expire:
Set-MsolUser -UserPrincipalName <name of the account> -PasswordNeverExpires $true
For example, if the name of the account is Ina@contoso.com, you'd type the command like this:
Set-MsolUser -UserPrincipalName Ina@contoso.com -PasswordNeverExpires $true
##############################################################################
Get-MSOLUser -UserPrincipalName <user ID> | Select PasswordNeverExpires
For example, to see the status for Ina@contoso.com, you'd type the following:
Get-MSOLUser -UserPrincipalName Ina@contoso.com | Select PasswordNeverExpires
###############################################################################
Office365 Device Access & Allow
###############################################################################
Open windows PowerShell as administrator(Run as administrator)
1. Set-ExecutionPolicy RemoteSigned //Press enter // press "Y" and Enter
2. $UserCredential = Get-Credential // Manage Exchange Online à Enter Global Admin Credentials
3. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection //Press Enter
4. Import-PSSession $Session // Press Enter
Run below command and collect the device ID of Quarantine device.
5. Get-MobileDevice -Mailbox Ina@contoso.com
Collect the Device ID and Run below command to add that device to the user.
6. Set-CASMailbox -identity Ina@contoso.com -ActiveSyncAllowedDeviceIDs "Device ID"
You can check the details of the devices by using below command.
7. Get-CASMailbox Ina@contoso.com | FL
####################################################################################################################
Incoming Mail Log Count
######################################################################################################################
Commands to connect PowerShell to Exchange Online.
$cred = Get-Credential
$session = New-PSSession -Verbose -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $session
Command to run message trace :
######################################################################################################################
$dateEnd = 05/01/2018
$dateStart = $dateEnd.AddDays(-30)
Get-MessageTrace -StartDate $dateStart -EndDate $dateEnd -RecipientAddress customercare@efreightsuite.com -PageSize 5000 | Select-Object Received, SenderAddress, RecipientAddress, Subject, Status, ToIP, FromIP, Size, MessageID, MessageTraceID | Export-csv C:\test.csv
Command for specific start date and end date:
Get-MessageTrace -RecipientAddress customercare@efreightsuite.com -StartDate 05/01/2018 -EndDate 05/15/2018 -PageSize 5000 | Select-Object Received, SenderAddress, RecipientAddress, Subject, Status, ToIP, FromIP, Size, MessageID, MessageTraceID | Export-csv C:\test.csv
######################################################################################################################
################################################################################################################################################################
# Script accepts 2 parameters from the command line
#
# Office365Username - Optional - Administrator login ID for the tenant we are querying
# Office365Password - Optional - Administrator login password for the tenant we are querying
#
#
# To run the script
#
# .\Get-DistributionGroupMembers.ps1 [-Office365Username admin@xxxxxx.onmicrosoft.com] [-Office365Password Password123]
#
#
# Author: Alan Byrne
# Version: 2.0
# Last Modified Date: 16/08/2014
# Last Modified By: Alan Byrne alan@cogmotive.com
################################################################################################################################################################
Group & Member List Export
################################################################################################################################################################
#Accept input parameters
Param(
[Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)]
[string] $Office365Username,
[Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)]
[string] $Office365Password
)
#Constant Variables
$OutputFile = "DistributionGroupMembers.csv" #The CSV Output file that is created, change for your purposes
$arrDLMembers = @{}
#Remove all existing Powershell sessions
Get-PSSession | Remove-PSSession
#Did they provide creds? If not, ask them for it.
if (([string]::IsNullOrEmpty($Office365Username) -eq $false) -and ([string]::IsNullOrEmpty($Office365Password) -eq $false))
{
$SecureOffice365Password = ConvertTo-SecureString -AsPlainText $Office365Password -Force
#Build credentials object
$Office365Credentials = New-Object System.Management.Automation.PSCredential $Office365Username, $SecureOffice365Password
}
else
{
#Build credentials object
$Office365Credentials = Get-Credential
}
#Create remote Powershell session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Office365credentials -Authentication Basic –AllowRedirection
#Import the session
Import-PSSession $Session -AllowClobber | Out-Null
#Prepare Output file with headers
Out-File -FilePath $OutputFile -InputObject "Distribution Group DisplayName,Distribution Group Email,Member DisplayName, Member Email, Member Type" -Encoding UTF8
#Get all Distribution Groups from Office 365
$objDistributionGroups = Get-DistributionGroup -ResultSize Unlimited
#Iterate through all groups, one at a time
Foreach ($objDistributionGroup in $objDistributionGroups)
{
write-host "Processing $($objDistributionGroup.DisplayName)..."
#Get members of this group
$objDGMembers = Get-DistributionGroupMember -Identity $($objDistributionGroup.PrimarySmtpAddress)
write-host "Found $($objDGMembers.Count) members..."
#Iterate through each member
Foreach ($objMember in $objDGMembers)
{
Out-File -FilePath $OutputFile -InputObject "$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($objMember.DisplayName),$($objMember.PrimarySMTPAddress),$($objMember.RecipientType)" -Encoding UTF8 -append
write-host "`t$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($objMember.DisplayName),$($objMember.PrimarySMTPAddress),$($objMember.RecipientType)"
}
}
#Clean up session
Get-PSSession | Remove-PSSession
################################################################################################################################################################
Export Email Count List
############################################################################################################
Commands to connect PowerShell to Exchange Online.
$cred = Get-Credential
$session = New-PSSession -Verbose -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $session
Command to run message trace :
$dateEnd = 05/01/2018
$dateStart = $dateEnd.AddDays(-30)
Get-MessageTrace -StartDate $dateStart -EndDate $dateEnd -RecipientAddress customercare@efreightsuite.com -PageSize 5000 | Select-Object Received, SenderAddress, RecipientAddress, Subject, Status, ToIP, FromIP, Size, MessageID, MessageTraceID | Export-csv C:\test.csv
Command for specific start date and end date:
Get-MessageTrace -RecipientAddress customercare@efreightsuite.com -StartDate 05/01/2018 -EndDate 05/15/2018 -PageSize 5000 | Select-Object Received, SenderAddress, RecipientAddress, Subject, Status, ToIP, FromIP, Size, MessageID, MessageTraceID | Export-csv C:\test.csv
The output of above command will give you up to 5000 results, you can always change the dates and run the commands.
######################################################################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment