Skip to main content

ServerCore + Create Test Users using Facebook

So Recently my VHD got corrupted and had to make the VHD Boot again work. Thankfully I had all the PowerShell one-liners I used to get my Lab up in less time.

First of all I will add 100 test users by following this awesome Hey Scripting Guys Blog Post.

To make things a bit clear I am on a workstation with RSAT for Active Directory installed and my DC is a servercore machine.

Just to give a hint when I need to run a cmdlet to get any information from the AD, I need to specify the name of the DC with -Server  parameter from where I want to get the information but a new connection will be opened and closed for each cmdlet invocation.

For Example :
Get-ADForest -Server dexservercore.dexter.com

Better way explained in Active Directory PowerShell Blog is to map a PSDrive for better performance. Since I have only one DC in my test environment , when I Import the ActiveDirectory Module it will automatically map a PSDrive on my remote workstation.





Now I don't want to add users like TestUser01, TestUser02... So I began to think from where can I get the data to create few test users for my Domain....and the answer to it is what better than FaceBook :P

Below are the steps I carried out:

Create a new Organizational Unit
I used the following cmdlet to create an OU named 'IT' under dexter.com
   New-ADOrganizationalUnit -Name IT -Path 'dc=dexter,dc=com' -ProtectedFromAccidentalDeletion:$false

Get the relevant data from Facebook

To get the some basic info for the User I used already available PowerShell Module for Facebook( credits to the Developer). On a how to use this module see my earlier post.


Set up a New FB Connection and be ready to retrieve data from Facebook 
 

 You can see that I have stored all my FB friends in $friends, but it doesn't return much information. What can be done here..there is an another cmdlet Get-FBObjectData which returns objects with greater deal of information. So just expand the property ID and pipe it and use as below



Better save this valuable data as a facebook.xml which I will use later.....

Create the AD Users 

Now I have all the information I could gather from Facebook into an XML file for later use. Now I will do some manipulation with the Objects I get from ...Below is the Script block which I used.


Above is the Script block that I used later from the PowerShell ISE.
First import the XML data into variable $facebookdata then do some Object manipulation in order to be consistent with the AD User attributes. Finally pipe it into the New-ADUser cmdlet with the -path parameter specifying the OU in which the Users need to be created.

Note that there is a -whatif parameter added at last to just check if we are headed in the right direction. Execute the Script block to get something like below ouput



If you read it properly it tells our success story :)
Go ahead and remove the -whatif parameter and execute the Script block again

When I run the script block I get two errors :
Below one is because some of my friends have same name and the other one is because of some formatting issues in the name of some friends.





Finally verify the User creation:



That's all for today.
Thank you!

Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

Azure DevOps Tips & Tricks - Find private REST APIs

Original source -  Azure DevOps Tip - Find private APIs Often working with Azure DevOps, I hit a wall trying to automate some tasks but there are no REST API's made public yet. It was one of those task of automating creation of Environments in multi-stage YAML based pipelines in AzDO. Quick research reveals that this has been requested in uservoice  (please upvote). Let's see one of the very simple ways to discover some of these APIs.