Alle indlæg af 3l33t

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 -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 “”)) { 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 -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

Using WMIC in Windows

Using WMIC in Windows:

  • List all installed Programs

Open Command Prompt as Administrator


wmic product get name, version, vendor

and press Enter.

After a few moments, a list will be displayed in the command prompt detailing the programs installed on the target computer.

  • If you want to save the results in a .html file


wmic /output:%USERPROFILE%\DESKTOP\InstalledSoftware.htm product get Name, Version /format:htable

and press Enter.

  • If you want to uninstall a program from the list

Echo Y|WMIC Product Where “Name='<INSERT PRODUCT NAME HERE>'” Call Uninstall


MacOS Terminal: Create a Bootable USB from an ISO Using “dd”

The .ISO file is a widely used disk image format and the standard format for bootable media. (Linux anyone?)

Here is a quick and easy way to make a bootable USB from a .ISO file, no 3rd party apps required.

Here are the terminal commands in order, followed by explanations of what they do:

Note: You’ll need to be an administrator to do this.

diskutil list

Lists out all disk drives and their volumes. Drives are labeled as disk0, disk1, disk2, etc. Volumes are labeled disk1s0, disk1s1, disk1s2, etc. For our purposes, we only care about the drive. In this case, we’re going to assume our flash drive is disk2.

diskutil unmountDisk disk2

The unmountDisk command unmounts all volumes of the given disk drive but keeps the drive itself visible to the computer (as opposed to the eject option that disconnects it entirely)

sudo dd if=/Users/kyle/Downloads/Linux.iso of=/dev/disk2 bs=8m

“sudo” tells the system to use root level (that is the system’s highest level) privileges to perform the following action.

“dd”  is an extremely basic, but powerful block level copy command built into all Linux and Unix operating systems (MacOS is UNIX based)

“if” stands for input file (a.k.a the source file or location). In our use-case, this is the .ISO file. In MacOS, if you have a finder window open, you can drag and drop the .iso into the terminal and it will auto-fill this file path.

“of” stands for “output file” (a.k.a the destination file or location). For us, this is our USB drive, disk2. The specific path for external drives is in “/dev”, hence /dev/disk2

“bs” stands for block size. dd copies data in blocks rather than on a file by file basis (this is why it’s so fast) and this command gives you the option to set how big each block is. There is a science to the ideal block size, but I don’t know it. 8m (MegaBytes) has consistently worked well for my uses.

The command will not show any progress until it’s done, but you can press control+t for status updates. With an average computer, this takes less than 5min to complete.

Once complete:

diskutil eject disk2

The USB drive can now safely be removed. Assuming that the iso is EFI-compatible, you can reboot your mac to test it.

Veeam Agent Installation (Linux)

-Veeam Agent Linux Debian 64 Bit-

sudo wget && dpkg -i ./veeamrelease.deb && apt update && apt install linux-headers-$(uname -r) && apt install veeam && veeamconfig ui

Outlook Data File Performance

Outlook Data File Performance

If you have a large .pst or .ost file, you may experience application pauses while you perform typical operations in Outlook. These typical operations include reading email messages, moving email messages, and deleting email messages.

The following list summarizes expected behavior based on the size of your Outlook data file.

  • Up to 5 GB: This file size should provide a good user experience on most hardware.
  • Between 5 and 10 GB: This file size is typically hardware dependent. Therefore, if you have a fast hard disk and lots of RAM, your experience will be better. However, slower hard disk drives, such as drives that are typically found on portable computers or early-generation solid-state drives (SSDs), experience some application pauses when the drives respond.
  • More than 10 GB: When the .ost file reaches this size, short pauses begin to occur on most hardware.
  • Very large (25 GB or larger): An .ost file of this size increases the frequency of short pauses, especially while you are downloading new email messages. However, you can use Send/Receive groups to manually sync your mail. For more information about Send/Receive groups, see the “Are you synchronizing many RSS feeds?” section.

HP Procurve Loop-Protection

Loop detection – without STP

According to the documentation:

Loop protection provides protection against loops by transmitting loop protocol packets out of ports on which loop protection has been enabled. When the switch sends out a loop protocol packet and then receives the same packet on a port that has a receiver-action of send-disable configured, it shuts down the port from which the packet was sent.

So it’s not doing anything fancy – just using its own protocol packet to detect loops back to the switch itself. Note this is different to Cisco’s loopback detection, which will detect a switchport looped back on itself – e.g. due to faulty wiring – but will not detect a cable run from one port to another on the same switch. Configuration is quick and easy, and it seems to work well. It should work well in any situation where you have edge ports that users might connect together, possibly via a ‘dumb’ switch that doesn’t forward STP BPDUs. These loop protection frames should be forwarded.

Let’s take a quick look at the configuration and operation on my lab switch, an HP 2910al-24G Procurve switch, running W.15.08.0012. The default configuration is for loop-protection to be disabled:

sw01pi# show loop-protect 

 Status and Counters - Loop Protection Information

 Transmit Interval (sec)     : 5           
 Port Disable Timer (sec)    : Disabled          
 Loop Detected Trap          : Disabled     

       Loop    Loop     Loop   Time Since  Rx           Port   
  Port Protect Detected Count  Last Loop   Action       Status  
  ---- ------- -------- ------ ----------- ------------ --------

In my lab, I’ve run a cable between ports 21 and 22, so we can simulate a loop. Currently both ports are shut down. Spanning-tree is disabled on this switch, so if I enable those ports, we’ve got a loop, and things will get messy. Let’s configure loop protection, and then enable the ports:

sw01pi# conf t
sw01pi(config)# loop-protect 
 disable-timer         Specify the number of seconds to wait before re-enabling
                       a disabled port.The default is 0, which will prevent 
                       automatically re-enabling the port
 [ethernet] PORT-LIST  Specify the ports that are to be added to/removed from 
                       loop protection.
 transmit-interval     Set time between packet transmissions.
 trap                  Specify loop protection traps that are to be 
sw01pi(config)# loop-protect 21-22
sw01pi(config)# loop-protect trap loop-detected 
sw01pi(config)# interface 21-22
sw01pi(eth-21-22)# enable

OK, let’s take a look at what’s happened with our ports:

sw01pi# show loop-protect 

 Status and Counters - Loop Protection Information

 Transmit Interval (sec)     : 5           
 Port Disable Timer (sec)    : Disabled    
 Loop Detected Trap          : Enabled     

       Loop    Loop     Loop   Time Since  Rx           Port   
  Port Protect Detected Count  Last Loop   Action       Status  
  ---- ------- -------- ------ ----------- ------------ --------
  21   Yes     No       0                  send-disable Down    
  22   Yes     Yes      1      2s          send-disable Down    
sw01pi#show log -r
---output truncated---
I 05/18/13 17:13:31 00077 ports: port 21 is now off-line
I 05/18/13 17:13:31 00077 ports: port 22 is now off-line
I 05/18/13 17:13:30 00898 ports: Loop Protect(62) has disabled port 22
I 05/18/13 17:13:30 00884 loop-protect: port 22 disabled - loop detected.
I 05/18/13 17:13:30 00076 ports: port 22 is now on-line
I 05/18/13 17:13:30 00076 ports: port 21 is now on-line

Pretty simple hey? One of the ports has been shut down, as expected. It has been logged, and an SNMP trap (OID: has been generated. We’ve got the “Port Disable Timer” at the default of “Disabled” – this means that the port will stay shut down until we take manual action. We’d like it to re-enable after 10s, so we configure this:

sw01pi(config)# loop-protect disable-timer 10

Now if we keep an eye on the output of show loop-protect we can see the Loop Count incrementing, as the port gets re-enabled, detects a loop, and shuts down again:

sw01pi# show loop-protect 

 Status and Counters - Loop Protection Information

 Transmit Interval (sec)     : 5           
 Port Disable Timer (sec)    : 10          
 Loop Detected Trap          : Enabled     

       Loop    Loop     Loop   Time Since  Rx           Port   
  Port Protect Detected Count  Last Loop   Action       Status  
  ---- ------- -------- ------ ----------- ------------ --------
  21   Yes     Yes      0                  send-disable Down    
  22   Yes     No       5       6s         send-disable Down    

So now you can set a disable timer, and once users remove the loop, their network ports will come back up, without needing any input from the local network admin. All up, this is an easy feature to configure, and should be used on all edge ports on Procurve switches.