How to send an email with PowerShell

emailThe asnwer to How to send an email with PowerShell is very simple: Send-MailMessage! I love this command! It’s simple and it works very well.
I have tested this only on PS 3.0, but the command is available for 4.0 and 5.0 as well. I’m not going to write down the whole lot of informations, if you want to have a deeper knoledge about this command, have a look at Microsoft’s Send-MailMessage CMDLET.

If you’re looking for a simple explaination including examples and issues I found with this command, keep reading.
It is important to understand the fact that you will require an SMTP server to connect to! I’ve only tested this with Microsoft Exchange 2010 so far.

Let’s say we want to send an email from, to, with Test001 as a subject, using as smtp server and an HTML body (Hello,<BR /> this is a test.<BR />Kind Regards,<BR />PowerShell).

That simple! You can also attach a file with -Attachments “data.csv”. As I said, I won’t be covering all of the options here but this is how to send an email with PowerShell!

I have had issues with our Exchange Environment to send emails every now and then, they would fail with this error: Unable to read data from the transport connection: net_io_connectionclosed.
The weird thing is that if I am to try to re-send this command a second later, it would get the email sent.

I found somebody on the internet having the same issue and the way he resolved it was better than the way I was working on. What this piece of code below does is very simple: it tries to send the email 5 times and if it fails 5 times then it’ll quit. (more…)

Read More

Preparing to configure Windows. Do not turn off your computer

One of the servers I was working on got stuck for over an hour, after the first round of Windows Updates, saying “Preparing to configure Windows. Do not turn off your computer“. It was an Hyper-V host (Physical) and as per the below screenshot, I was able to gather this through iDRAC (DELL Server). I was almost 100% sure that this was stuck with something and actually not doing anything. The procedure will apply to both Windows Servers and Windows Clients.
Before powering it off and raise the risk to compromise the OS, I tried the below which worked successfully. Before trying the procedure below, try to press CTRL+ALT+DEL once and see if this “unlocks” it.

Preparing to Configure Windows. Do not turn off your computer.


If CTRL+ALT+DEL doesn’t fix it, then it is most likely getting stuck because of TrustedInstaller in a stopping state. This is how I figured out it was TrustedInstaller and how I remotely killed the process.

  • From any machine run Services.msc as an administrator: note that the account you use must have admin rights on the server you’re having troubles with! So if you’re in a domain, Run as a Different user and use your administrative account to launch services.msc. If you’re logged on with an account that already has admin rights on the server having troubles, then just run services.msc.
  • Click on Action -> Connect to another computer.
    Connect to Another Computer
  • Type the hostname (or IP) of the remote machine having troubles and click OK.

Read More

Enable GUI on Windows Server 2016 Technical Preview 2

Microsoft released Windows Server 2016 Technical Preview 2 and lots of people found a little surprise: no graphic interface!
During the installation though, this wasn’t mentioned, you would only see two options:

  • Windows Server Technical Preview 2
  • Windows Server Technical Preview 2 (with local admin tools)

Nothing about the installation being server core. Whether you choose the first or the second option you’re still going to end up with no GUI. Note that Server Manager will still open up.

In order to enable the GUI on Windows Server 2016 follow the steps below.

  1. Open Server Manager (if not already opened).
  2. Click Add Roles and Features Wizard.
  3. Click on Features from the left pane.
  4. Expand User interfaces and infrastructure and then select Server Graphical Shell (more…)

Read More