Lab: Connect to your ServerCore using remoting - step by step

The next part in my Lab setup now that I’ve gotten network configured is to actually no longer touch my new Lab machine…

While that might sound strange at first, the reason for this is simple. My Lab should be a headless server, stuffed in a cabinet somewhere with power and a network connection and I should be able to do ALL my management tasks remotely.

This should be a simple task you’d say, but for the sake of clarity [and to learn this process better myself] I have decided to write down all the steps required to do this.

Lab: Intel NUC with Windows ServerCore 2012R2

Since I’ve decided to get more serious about updating my skills and knowledge again [also why I started blogging], I thought about getting a proper lab setup.

The goal is to have a small, portable but powerful Hyper-V based lab which I can carry along with me from home and to work if need be. Now I tend to have a test setup on my home machine and one on my work laptop, depending on what I need at that moment. Using this portable lab I want to make everything I need accessible from one location.

Configuring PowerShell remoting through GPO


I’m loving the way Microsoft is currently pushing PowerShell as THE go-to tool required to manage all your solutions.

I’m at a loss however at why they aren’t providing out of the box solutions so that you can manage all of your workstations/servers through PowerShell. Sure, you can head over to every machine and configure PowerShell using

Enable-PSRemoting

However I can understand that people have better things to do with their time [I sure do!]

Importing users from Active Directory into Office 365

Today I ran into an issue where I had to quickly import x amount of users into an empty trial tenant from
Office 365 in order for to prepare the future mail migration.

Because I'm trying to get everything running through PowerShell, I thought this would be a nice moment to
document everything for future use and for other people to see how it's done [or give tips 😉 ]

Getting user information from Active Directory

First of all I had to get the current user information from Active Directory in a format that I can use in
Office 365.

So we start up PowerShell on the Windows 2008R2 Standard server and get all the details I need:

Import-Module -Name ActiveDirectory

Get-ADUser -Filter *

Now this would give me all the users in the entire domain, something I'm not quite looking for.

So in order to narrow it down, I'll just query all the users in a specific OU using the SearchBase parameter:

Get-ADUser -Filter * -SearchBase 'OU=Users,OU=MyBusiness,DC=Contoso,DC=COM'

This is better, however now I notice that in my case I have some subfolders with disabled/template users.
Again, I'd like to narrow it down to ONLY the users in the specific OU, no recursion.
For this I will need to further define my query using SearchScope:

Get-ADUser -Filter * -SearchBase 'OU=Users,OU=MyBusiness,DC=Contoso,DC=COM' -SearchScope 1

This gives me all the results I would like to have, but maybe a bit too much detail for me to export.

In order to see what properties I'd like to export, I need to know what properties I would like to
import on the Office 365 side of things:

    • FirstName
    • LastName
    • DisplayName
    • UserPrincipalName
    • UsageLocation

I can't get all of those properties from my current AD query, but those that I'm able to get,
I can provide in the format I would like them to be in.

The details I can get from AD are

    • FirstName = GivenName
    • LastName = SurName
    • DisplayName = Name
    • UserPrincipalName = EmailAddress

Using the property parameter we can get the users' email address and using Select-Object we output the
information in the format we would like to have it:

$Users = Get-ADUser -Filter * -SearchBase 'OU=Users,OU=MyBusiness,DC=Contoso,DC=COM' -SearchScope 1 -Property EmailAddress | Select-Object -Property @{L='FirstName';E={$_.GivenName}{,@{L='LastName';E={$_.SurName}},@{L='DisplayName';E={$_.Name}},@{L='UserPrincipalName';E={$_.EmailAddress}}

Presto-chango!

I can now export this information to a csv file:

$Users | Export-CSV -NoTypeInformation -Path C:\ADUsersExport.csv -Delimiter ','

Creating Office 365 users based on exported Active
Directory data

Now that we've exported our required data, we can simply import this data into our Office 365 tenant
account.

Using the Connect-O365 function which I've created in the Connect to Office 365 using PowerShell post,
you can easily perform bulk operations like this:

Connect-O365 -User Admin@contoso.onmicrosoft.com

Once connected, we will need to collect/set some default data required for our bulk user import:

$FilePath = 'C:\ADUsersExport.csv'
$Users = Import-Csv -Path $FilePath -Delimiter ','
$UsageLocation = 'NL'

Change the UsageLocation according to your requirements.

Now we've got all the information we need to create our new user accounts!

Foreach ($User in $Users) {
  New-MsolUser -FirstName $User.FirstName -LastName $User.LastName -DisplayName $User.DisplayName -UserPrincipalName $User.UserPrincipalName -UsageLocation $UsageLocation
  }

There we go, all the users are imported in your tenant!

Some tips in case you're running into errors:

    • Be sure to have the email address domain configured in your Office 365 tenant as accepted
      domain!
    • Be sure to have all your AD information filled in!

You will get automatically assigned passwords for these created accounts and you're good to go 🙂

Connect to Office 365 using PowerShell

In order to manage your Office 365 tenant(s) using PowerShell, there are some pre-requisites required.

  1. Ensure you are running Windows 8.1, Windows 8, or Windows 7.
  2. Make sure you have the .NET Framework 3.51 feature [enabled by default on Windows 8 and up]
  3. Make sure you have the latest updates. It is important to run this after you install .NET Framework 3.51, so you get updates for that in addition to updates for your operating system.
  4. Install the Microsoft Online Services Sign-In assistant. Even though the link provided should work, you should always look up the latest version [see next link].
  5. Install the Windows Azure Active Directory (Azure AD) module for the appropriate version of your operating system.

Once these requirements are installed, you can continue to connect to your tenant using the following function: