Useful powershell scripts
These Useful powershell scripts can help you manage your environment:
- Robocopy to copy content from A to B
- How to get list of members in an Office 365 Distribution List
- Room Resource calendar shows as "busy" instead of details
- Configure a SharedMailbox to keep a copy of the sent emails
User account locks
Import-Module activedirectory
$users = Search-ADAccount -LockedOut | Select-Object -ExpandProperty SamAccountName
ForEach ($user in $users)
{
$test = Get-AdUser $user -Properties *
$Body = $test.CN + " " + "account was locked out. It is now unlocked"
Send-MailMessage -To $test.Manager -Subject "Below Users LAN ID is locked" -SmtpServer "smtp.gmail.com" -From "This email address is being protected from spambots. You need JavaScript enabled to view it. " -Body $Body
}
Search-ADAccount -LockedOut | Unlock-ADAccount
To work with Powershell vs Exchange, first of all install Visual Studio Code on your computer, I recommend it to save the scripts, then do:
- First of all install PS 7.4.4 on your desire computer by visiting this link: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4#msi
- Run "pwsh.exe"
- Execute: Install-Module -Name ExchangeOnlineManagement
- Connect-ExchangeOnline -UserPrincipalName
This email address is being protected from spambots. You need JavaScript enabled to view it.
Edge, Firefox or similar will open, and once you login you can go back in again to Powershell and start executing some code
2. How to get list of members in an Office 365 Distribution List
- Execute:
Get-DistributionGroup -Identity "This email address is being protected from spambots. You need JavaScript enabled to view it. " -ResultSize Unlimited | Select Name, PrimarySMTPAddress, RecipientType | Export-CSV "C:\Temp\Distribution-List-Members.csv" -NoTypeInformation -Encoding UTF8
Get list of members from a Distribution Group
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName This email address is being protected from spambots. You need JavaScript enabled to view it.
Get-AdGroupMember -identity "MFA-AD-GROUP" | select name > list.txt
Get-DistributionGroupMember -identity "Exchange Distribution List" | format-list
Add-DistributionGroupMember -identity "Exchange Distribution List" -member "New User 1"
get-adgroup -filter * | sort name | select Name
3. Room Resource calendar shows as "busy" instead of details
Get-CalendarProcessing -Identity Dessau | fl
Set-CalendarProcessing -Identity Kirby.Laing -DeleteComments $true-DeleteSubject $true
The key command to run, is this thou:
Set-MailboxFolderPermission -Identity Kirby.Laing:\calendar -User default -AccessRights LimitedDetails
4. Configure a SharedMailbox to keep a copy of the sent emails
- set-mailbox finance -MessageCopyForSentAsEnabled $true
- set-mailbox finance -MessageCopyForSendOnBehalfEnabled $true
- set-mailbox finance -UseDatabaseQuotaDefaults $false
References
Comments powered by CComment