Skip to main content

Posts

Showing posts with the label ADUsers

PowerShell + AD + Pester : create new user using template Part 2

It seems like it has taken me forever to post this one. I had this one almost ready but then I asked few questions around, read a lot of posts and had to rewrite the pieces of the post, to sum it all it has been an eye opening when trying to test PowerShell code which interacts with Infrastructure. Below pic depicts my state at this point ( revelation to a whole new world). [ credits : movie "V for Vendetta"] In the last post , we laid the foundation for our Function. Go back and check the code their as we start from where we left off. In this post we dive straight into the third context for our Pester tests : Context  "User Creation"    It  should return Object when -Passthru specified (New addition)   It  should take OU Path from template User.    It  should only copy allowed set of attributes from the User (by default).    It  should allow copying a subset of allowed set of attributes .     Note - ...

PowerShell + AD + Pester : Create new user using template - Day 1

I did a blog post, way back to create new users in AD using already existing user as a template,  but many people commented about using the template didn't copy the Home Directory, logon script path, group membership etc. So finally I tried my hands on writing a Function which does a better job at this. The idea is to write a New-ADUserFromTemplate function, to which you specify all the properties you want copied while creating a User from an existing User (template User). Let's make it fun and write the code using the Behavior Driven development approach using Pester. This will probably a 2 part series : Day 1 - Getting the Ground Work ready, Pester tests for Parameter, Help & Module dependency . Day 2 - Write Pester tests and code for the actual function. Refactoring the Code. So we plan to do BDD or TDD here which means we write tests first and then follow the below cycle :

PowerShell + SCCM Tip: Get MachineName for a User

While doing Application deployments , we have cases where the User forgets to specify the Machine Name to which a software needs to be deployed to. We use Query-Based Deployment rules in ConfigMgr where we add the machine names to a Collection named after the Application..have already automated this process ;) But if the machine name is not specified then we either: Get the Machine name from SCCM Reports if available. Drop an email to the Requester for the same For getting the machine name for a User in ConfigMgr 07 we use the Reports obviously :D The report is located under "Users" node in ConfigMgr Reports page. But actually this can be retrieved using WMI/CIM too. The Class which has this info is SMS_R_System under namespace Root/SMS/site_<SiteCode> and let's take a look at it. Note: Before going further I have already set the ComputerName parameter and namespace parameter in the $PSDefaultParameters. Below is how you do it in...

[PowerShell + WMI Eventing ] AD Group Modified --> Run a PowerShell Script

I knew it would be a great learning opportunity when Francois-Xavier Cat Sir  agreed to take me in his team for the Winter Scripting Games this year. FX Sir posted about this great Script which will monitor your AD Group for any changes and then email you the changes if any. You can find the blog post here Now while reading the post I had a question...So I did comment on the post there: Well until recently I found out that it could be done very easily. So in today's blog post I will show how to trigger a PowerShell Script when a Group in AD is modified. I got the answer to above question while reading this great book on WMI by Ravi Sir suggested to me by Laerte Junior Sir .  You can find the book here If you haven't guessed it by now the answer to making it possible is --- Wait for it " WMI Eventing ". I read this very cool thing on a blog:                  "The M in W M I stands for Magic"  - Ki...

Use PowerShell to Create New AD Users using a Template

To use and existing account as a template to create new users one would use the good old "Active Directory Users and Computers" , right? by right-clicking on the User to be used as template and selecting "Copy" which will prompt something like below: But this blog is  meant for doing things using PowerShell. To quickly get me started I was tempted to use "Active Directory Administrative Center" on Server 2012, so that I could see the PowerShell history for the my actions( Yeah! you can do that now !!) but there was no method to do that in AD Admin Center :O , See below   The User "Dexter POSH" is the member of the group "RemotePOSHAdmins" under the OU "POSHAdmins" in my domain. I want to add a new User here using the dexterposh user account as the template. At first I thought of simply getting the User information using Get-ADUser and piping it into New-ADUser cmdlet (because it accepts pipeline input of type ...