Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By : Thomas Lee, Ed Goad
Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By: Thomas Lee, Ed Goad

Overview of this book

This book showcases several ways that Windows administrators can use to automate and streamline their job. You'll start with the PowerShell and Windows Server fundamentals, where you'll become well versed with PowerShell and Windows Server features. In the next module, Core Windows Server 2016, you'll implement Nano Server, manage Windows updates, and implement troubleshooting and server inventories. You'll then move on to the Networking module, where you'll manage Windows network services and network shares. The last module covers Azure and DSC, where you will use Azure on PowerShell and DSC to easily maintain Windows servers.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Adding users to AD using a CSV file


As mentioned several times in this book, https://www.spiceworks.com/ has a busy PowerShell support forum (accessible at https://community.spiceworks.com/programming/powershell). A frequently asked (and answered) question is: How do I add multiple users using an input file? This recipe does just that. You start with a simple CSV file containing the details of the users you wish to add. This script uses a CSV file and adds the users contained in the CSV.

Getting ready

This recipe assumes you have a domain setup and that you have created the IT organizational unit.

How to do it...

  1. Import a CSV file containing the details of the users you want to add to AD:
$Users = Import-CSV -Path C:\FooUsers.Csv
  1. Add the users using the CSV:
ForEach ($User in $Users) { $Prop = @{} $Prop.GivenName = $User.Firstname $Prop.Initials = $User.Initials $Prop.Surname = $User.Lastname $Prop.UserPrincipalName = 
       $User.UserPrincipalName+"@reskit.org" $Prop.Displayname = $User.firstname...