Tuesday, March 28, 2023

Using PowerShell to Provide a List of Mailboxes by Mailbox Size and Export to CSV File

To provide a list of mailboxes by size in M365 and export it to a CSV file using PowerShell, you can use the following command:

Get-MailboxStatistics -ResultSize Unlimited | Sort-Object TotalItemSize -Descending | Select-Object DisplayName, ItemCount, ` @{Name="TotalItemSize(MB)";Expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, ` StorageLimitStatus, LastLogonTime | Export-Csv -Path "C:\MailboxSizes.csv" -NoTypeInformation

This command uses the Get-MailboxStatistics cmdlet to retrieve mailbox statistics for all mailboxes in the organization, sorts the results by the TotalItemSize property in descending order, selects the DisplayName, ItemCount, TotalItemSize in MB, StorageLimitStatus, and LastLogonTime properties, and then exports the results to a CSV file located at "C:\MailboxSizes.csv".

Note that the expression used to calculate the TotalItemSize in MB converts the value from bytes to MB and rounds it to two decimal places using the Round method. The -NoTypeInformation parameter is used to exclude the object type information from the CSV file to make it easier to read.


Tuesday, March 14, 2023

Enabling Previous Versions / Volume Shadow Copy on Windows 10 and 11 Via Command Line / PowerShell

 Volume Shadow Copy (VSS) is a feature in Windows that allows you to create snapshots of your system at different points in time. These snapshots are called "previous versions," and they can be used to recover files and folders that have been accidentally deleted or changed. It should be noted that Volume Shadow Copy does not take the place of backups, as the previous versions are stored on the same system as the data it is making a copy of, but it can be used to quickly and easily restore deleted or overwritten files and directories. 

VSSAdmin, also known as Volume Shadow Copy Service Administration, is a command-line utility tool used in Microsoft Windows operating systems and is used to manage and control the behavior of the Volume Shadow Copy Service, including creating, deleting, and modifying shadow copies.

To enable Volume Shadow Copy and create previous versions using VSSAdmin on Windows 10 or Windows 11, follow these steps:

Open Command Prompt as an administrator. To do this, click the Start button, type "powershell" in the search bar, right-click on the first result and select "Run as administrator."

Once launched, type the following command and press Enter to check if Volume Shadow Copy is already enabled:

vssadmin list shadowstorage



Since I don't yet have VSS enabled, I get the following result:



Enable the Volume Shadow Service:

vssadmin resize shadowstorage /for=C: /on=C: /maxsize=5GB


Once enabled, you can then use the wmic utility to create your first shadow copy:

wmic shadowcopy call create Volume='C:\'



You can learn more about the components of Volume Shadow Copy on Microsoft Learn - VSS Deep Dive