Tag-arkiv: Udvalgt

Exchange – Useful Powershell Commands

Here is some useful Powershell Commands for reports:

  • Connect to Office 365 / Exchange Online
    • Open the Windows PowerShell as Administrator
    • Execute the following command $LiveCred = Get-Credential and enter the admin credentials in the popup dialog.
    • Execute the following commands:
      $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
      Import-PSSession $Session

and enter the admin credentials in the popup dialog.
*Press enter at Import-PSSession $Session

List All Email Adresses in a .txt file

Get-recipient -resultsize unlimited | select Name -expand emailaddresses > c:\emailadresses.txt

List All Mailbox Sizes in a .html file

Get-Mailbox –ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | convertto-html DisplayName, LastLoggedOnUserAccount,  LastLogonTime, TotalItemSize, ItemCount, @{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}} | set-content c:\mailboxsizes.html

List All Mailbox Permissions in a .csv file

Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne “NT AUTHORITY\SELF” -and $_.IsInherited -eq $false} | Select Identity,User,@{Name=’Access Rights’;Expression={[string]::join(‘, ‘, $_.AccessRights)}} | Export-Csv -NoTypeInformation c:\mailboxpermissions.csv

List Mailboxes by mailbox databases

Get-Mailbox | Sort database, name | Format-Table name, database

  • Here is some useful Powershell Commands for Export/Import:

Granting User Rights for Mailbox Exports in Exchange 2010

New-ManagementRoleAssignment -Role “Mailbox Import Export” -User Administrator


New-MailboxImportRequest -Mailbox “Administrator” -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst” 


New-MailboxExportRequest -Mailbox administrator -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst”


foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst” }


foreach ($i in (Get-Mailbox -OrganizationalUnit “domain.dk”)) { New-MailboxExportRequest -Mailbox $i -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst” }


Get-MailboxExportRequest | Get-MailboxExportRequestStatistics


GetMailboxExportRequest -Status Completed | Remove-MailboxExportRequest

Full Accesss to All Mailboxes

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq ‘UserMailbox’) -and (Alias -ne ‘Admin’)} | Add-MailboxPermission -User Administrator@domain.dk -AccessRights fullaccess -InheritanceType all

  • Here is some useful Powershell Commands for Database Management:

List Mailboxes by mailbox databases

Get-Mailbox | Sort database, name | Format-Table name, database

Move all mailboxes from one database to another database

1. Launch the Exchange Management Shell > Firstly lets get the names of my Databases, then I can simply copy and paste them into the move mailbox command.


Get-Mailbox -Database “Source Database Name” -ResultSize Unlimited | New-MoveRequest -TargetDatabase “Target Database Name

2. The Mailbox moves should then be queued, depending on how many there are, this can take some time to complete.

3. To check on progress issue the following command;

Get-MoveRequestStatistics -MoveRequestQueue “Target Database Name

4. When complete you should remove the movement requests like so;

Get-MoveRequest | where {$_.status -eq “Completed”} | Remove-MoveRequest

5. That’s all the ‘user’ mailboxes, but your source database server may have system mailboxes in it. These will be either Arbitration mailboxes, or Archive Mailboxes (or both). I don’t have any archive mailboxes, but I do have Arbitration mailboxes. To find out for your databases, use the following commands;

Get-Mailbox -Database “Source Database Name” -Arbitration

Get-Mailbox -Database “Source Database Name” -Archive

6. To move Arbitration and Archive mailboxes, use the following commands;

Get-Mailbox -Database “Source Database Name” -Arbitration | New-MoveRequest -TargetDatabase “Target Database Name

Get-Mailbox -Database “Source Database Name” -Archive | New-MoveRequest -TargetDatabase “Target Database Name

7. You can monitor progress with the same command you used in step 3, -and remove the move requests with the same command you used in step

Linux – Expand a VM with GParted

Nowadays it’s casual to use VMs for development environments. It’s also casual that projects grow and you run out of disk space inside the VMs. Luckily, on the host there’s always enough space available which can be assigned to an existing VM (isn’t it?).

Expanding the partition in the VMware Hardware options / hard disk details is pretty easy. Just stop the VM, click the expand button and increase as required:

Now we have some more space for partitions in our VM but we want to increase the size of an existing partition. To manage the partitions, we’re using GParted, which is available as bootable ISO-Image.

Assign the downloaded ISO in your VMware CD-ROM drive and boot from it. You can select the boot device if you hit ESC right after powering on the VM.

If you’re running Ubuntu in your VM, it is likely that there might be a swap partition (/dev/sda5 here) between the main partition and the aforementioned created, unallocated new space and your partitions might look like this:

What we want to achieve now, is to merge the 10 GB unallocated space at the end of the list to the /dev/sda1 partition.

First, we’ll select /dev/sda2 (NOT /dev/sda5!):

Then, we click “Resize/Move”:

Next, we increase the size of /dev/sda2 to use all available space:

Now we select /dev/sda5 and click Resize/Move again:

In this step, we move /dev/sda5 inside /dev/sda2 to right end:

Then again, we select /dev/sda2:

After clicking Resize/Move now we shrink /dev/sda2 to the size of /dev/sda5 by moving the left arrow to the right until it is blocked:

Now we select /dev/sda1 again:

After clicking “Resize/Move” again, we finally can expand /dev/sda1 to the right:

The final step is hitting the “Apply” button, confirm everything, cross fingers and wait for the operations to succeed.

As GParted already tells you in almost every step: Be careful with what you’re doing and create a backup before you’re trying to modify your partitions!

After the resize you may need to also expand the root partition.

For getting the available Physical Extend size run.

# vgdisplay

Check Available Physical Size

Check Available Physical Size

There are 4607 free PE available = 18GB Free space available. So we can expand our logical volume up-to 18GBmore. Let us use the PE size to extend.

# lvextend -l +4607 /dev/vg_tecmint/LogVol01

Use + to add the more space. After Extending, we need to re-size the file-system using.

# resize2fs /dev/vg_tecmint/LogVol01

Now if we check the vg available Free PE it will be 0.

# vgdisplay