Home Powershell Useful Powershell Commands (that I keep forgetting)

Useful Powershell Commands (that I keep forgetting)

by padd

I keep on forgetting these commands so I thought that I would pop them somewhere that I can remember.

Exchange Online

Create List of Licenced Mailboxes

#From Exchange Online shell
Get-Mailbox -Resultsize Unlimited | where {($_.recipienttypedetails -ne "Discoverymailbox") -and ($_.recipienttypedetails -ne "RoomMailbox") -and ($_.skuassigned -eq "True") }

Enable Litigation Hold on all Licenced 0365 Mailboxes

#From Exchange Online shell
$Mailboxes = Get-Mailbox -Resultsize Unlimited | where {($_.recipienttypedetails -ne "Discoverymailbox") -and ($_.recipienttypedetails -ne "RoomMailbox") -and ($_.skuassigned -eq "True") -and ($_.LitigationHoldEnabled -ne $true)}
$Mailboxes | Set-Mailbox -LitigationHoldEnabled $true

Turn off Junk Mail

Get-Mailbox <mailboxName>| Set-MailboxJunkEmailConfiguration -Enabled $false

Move a Mailbox Migration into a Smaller Batch

#From Exchange Online shell
New-MigrationBatch -Name "Joe Bloggs" -UserIds "Joe.Bloggs@JoeBloggsDomain.co.uk" -DisableOnCopy -AutoStart -NotificationEmails ExchangeAdmin@JoeBloggsDomain.co.uk

Exchange Server 2013

Check Database whitespace

#From an Exchange Management Shell
Get-MailboxDatabase -status | select Name, AvailableNewMailboxSpace

Windows 10

Clear down Windows Credential Manager

Use this script to clear down the credential cache in Windows quickly. It is useful when Outlook is repeatedly asking for a password and locking the user’s account out.

#Clear down All Office Applications
cmdkey /list | ForEach-Object{if($_ -like "*Target:*" -and $_ -like "*microsoftOffice"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}

#Clear down Microsoft Teams
cmdkey /list | ForEach-Object{if($_ -like "*Target:*" -and $_ -like "*msteams*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}

#Clear down Outlook 365 Credentials
cmdkey /list | ForEach-Object{if($_ -like "*Target:*" -and $_ -like "*outlook.office365.com*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}

#Clear down OneDrive
cmdkey /list | ForEach-Object{if($_ -like "*Target:*" -and $_ -like "*onedrive*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}

#Clear down Everything
cmdkey /list | ForEach-Object{if($_ -like "*Target:*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}


How to install RSAT tools on Windows 10 1809 and above

Starting with Windows 10 1809, RSAT tools have been migrated to windows features on demand. The quickest way to install them is to run the following from an elevated powershell prompt.

Get-WindowsCapability -Online | ? Name -like Rsat.* | Add-WindowsCapability -Onlin

You may also like

1 comment

Andrejs 26th February 2021 - 6:21 pm

Hi,

This script does not delete:
Target: LegacyGeneric:target=OneDrive Cached Credential Business – Business1

Can you assist, how to improve this script?

Reply

Leave a Reply to Andrejs Cancel Reply

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.