Nazaudy, a spark in your curious mind

Useful powershell scripts

These Useful powershell scripts can help you manage your environment:

 

  1. Robocopy to copy content from A to B
  2. How to get list of members in an Office 365 Distribution List
  3. Room Resource calendar shows as "busy" instead of details
  4. 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:

  1. 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
  2. Run "pwsh.exe"
  3. Execute: Install-Module -Name ExchangeOnlineManagement 
  4. 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

  1. 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