WolfTech Active Directory: PowerShell

Similar documents
SUNGARD SUMMIT 2007 sungardsummit.com 1. Microsoft PowerShell. Presented by: Jeff Modzel. March 22, 2007 Course ID 453. A Community of Learning

Microsoft. Jump Start. M3: Managing Windows Server 2012 by Using Windows PowerShell 3.0

POWERSHELL (& SHAREPOINT) This ain t your momma s command line!

Windows PowerShell Fundamentals

Acknowledgments Finding Your Way Around Windows PowerShell p. 1 Getting Started with Windows PowerShell p. 3 Installing Windows PowerShell p.

PowerShell for Exchange Admins

Exploring PowerShell. Using Windows PowerShell

Automating Microsoft

Microsoft Windows PowerShell v2 For Administrators

Jeffrey Snover Distinguished Engineer & Lead Architect Jason Helmick Senior Technologist, Concentrated Technology

Windows PowerShell. 3.0 Step by Step. Ed Wilson

You Should Be Using PowerShell Aaron Kaiser Senior Technology Support Specialist Parkway School District

POWERSHELL FOR NEWBIES Getting started with PowerShell 4.0. Jeffery Hicks

Windows PowerShell Essentials

Windows PowerShell Cookbook

Powershell Management for Defender

Windows Server 2008 R2: Server Management and PowerShell V2

Things I wish I d known when I started using PowerShell

OPAS Prerequisites. Prepared By: This document contains the prerequisites and requirements for setting up OPAS.

Lab Answer Key for Module 1: Installing and Configuring Windows Server Table of Contents Lab 1: Configuring Windows Server

Lab Sample Solutions. Chapter 3

Introduction to PowerShell by Guy Thomas

Managing Windows Environments with Group Policy

Using Windows PowerShell to Manage SharePoint 2010

Windows Server 2008 R2: What's New in Active Directory

ActiveRoles Management Shell for Active Directory

PowerShell for Dummies

WolfTech Active Directory: SCCM 101

Forefront Management Shell PowerShell Management of Forefront Server Products

Managing Windows Environments with Group Policy 50255D; 5 Days, Instructor-led

Track User Password Expiration using Active Directory

Log Analyzer Reference

DEPLOYMENT GUIDE DEPLOYING F5 AUTOMATED NETWORK PROVISIONING FOR VMWARE INFRASTRUCTURE

Windows Command-line Automation Techniques for Dell EqualLogic PS Series Arrays

WHITE PAPER POWERSHELL FOR DUMMIES HOW TO KEEP TRACK OF

WolfTech Active Directory: OU Administration

Hands-On Lab. Lab 01: Getting Started with SharePoint Lab version: Last updated: 2/23/2011

5/13/2009. Dejan Foro Speaker

MS-50255: Managing, Maintaining, and Securing Your Networks Through Group Policy. Course Objectives. Required Exam(s) Price.

Click Studios. Passwordstate. Password Discovery, Reset and Validation. Requirements

Tips and Tricks Guide tm. Windows Administration. Don Jones and Dan Sullivan

Outline SSS Microsoft Windows Server 2008 Hyper-V Virtualization

Intel vpro Technology Module for Microsoft* Windows PowerShell*

Buffalo Technology: Migrating your data to Windows Storage Server 2012 R2

Automating. Administration. Microsoft SharePoint with Windows. PowerShell 2.0. Gary Lapointe Shannon Bray. Wiley Publishing, Inc.

What we are going to cover...

Clearswift SECURE Exchange Gateway Installation & Setup Guide. Version 1.0

REST API Getting Started Guide

Facebook Twitter YouTube Google Plus Website

A layman s guide to PowerShell 2.0 remoting. Ravikanth Chaganti

IceWarp Server. Log Analyzer. Version 10

6422: Implementing and Managing Windows Server 2008 Hyper-V (3 Days)

Virtualization Hyper-V host scale and scale-up workload support

Implementing and Managing Windows Server 2008 Hyper-V

Click Studios. Passwordstate. Installation Instructions

Intel vpro Technology Module for Microsoft* Windows* PowerShell* Revision March 2012 Document ID: 1057

Step-By-Step Guide to Deploying Lync Server 2010 Enterprise Edition

IceWarp to IceWarp Server Migration

WolfTech Active Directory: Diagnostic Tools

vsphere Auto Deploy Update 1 ESXi 5.0 vcenter Server 5.0 EN

Windows PowerShell 2.0

Preparing an IIS Server for EmpowerID installation

Automatizace Private Cloud. Petr Košec, Microsoft MVP, MCT, MCSE

Implementing and Managing Microsoft Server Virtualization

The Exchange Management Shell

Module 4. Managing Groups. Contents: Lesson 1: Overview of Groups 4-3. Lesson 2: Administer Groups Lab A: Administer Groups 4-36

SPHOL205: Introduction to Backup & Restore in SharePoint Hands-On Lab. Lab Manual

EXAM Designing and Implementing a Server Infrastructure. Buy Full Product.

MS 50255B: Managing Windows Environments with Group Policy (4 Days)

Configuring the Basic Settings of an ESXi Host with PowerCLI

Automating Tasks Using PowerShell Scripting

10215A Implementing and Managing Microsoft Server Virtualization

Using Management Shell Reports and Tracking User Access in the NetVanta UC Server

NovaBACKUP xsp Version 15.0 Upgrade Guide

DocAve 6 SDK and Management Shell

Unidesk 3.0 Script to Increase UEP Size for Persistent Desktops

Setting Up ALERE with Client/Server Data

Quick Introduction System Requirements Main features Getting Started Connecting to Active Directory... 4

HP Data Protector. Granular Recovery Extension User Guide for Microsoft Exchange Server. Software Version: Document Release Date: June 2014

How to Create a Delegated Administrator User Role / To create a Delegated Administrator user role Page 1

Troubleshoot Using Event Log Mining

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Partie Serveur Lab : Implement Group Policy. Create, Edit and Link GPOs. Lab : Explore Group Policy Settings and Features

ICT Professional Optional Programmes

Windows Scheduled Task and PowerShell Scheduled Job Management Pack Guide for Operations Manager 2012

ecopy ShareScan 5.0 SQL installs guide

The safer, easier way to help you pass any IT exams. Exam : Core Solutions of Microsoft SharePoint Server 2013.

WHITE PAPER BT Sync, the alternative for DirSync during Migrations

DottsConnected SHAREPOINT 2010 ADMIN TRAINING. Exercise 1: Create Dedicated Service Accounts in Active Directory

How to monitor AD security with MOM

Backing Up and Recovering Your Server

Course Syllabus. Implementing and Managing Windows Server 2008 Hyper-V. Key Data. Audience. At Course Completion. Prerequisites

StoreGrid Backup Server With MySQL As Backend Database:

Postgres Plus xdb Replication Server with Multi-Master User s Guide

Index C, D. Background Intelligent Transfer Service (BITS), 174, 191

# Demo: jak to działa?

How To Install Powerpoint 6 On A Windows Server With A Powerpoint 2.5 (Powerpoint) And Powerpoint On A Microsoft Powerpoint 4.5 Powerpoint (Powerpoints) And A Powerpoints 2

AddLocalUser AddLocalGroup AddLocalUserToLocalGroup AddDomainUserToLocalGroup AddDomainGroupToLocalGroup

Transcription:

WolfTech Active Directory: PowerShell March 7th, 2012 2-4pm Daniels 201 http://activedirectory.ncsu.edu

What we are going to cover... Powershell Basics Listing Properties and Methods of Commandlets.Net Libraries Available Modules Securing Powershell Scripting Regular Expressions Powershell ActiveDirectory Module PSRemoting Server Administration - Roles

Core Cmdlets A PowerShell cmdlet is a pre-compiled command that can be invoked by the PowerShell runtime. There are many that come built-in to the runtime and many more can be loaded into the environment Cmdlets have a Verb-Noun naming convention Get-Command Get-Help Sort-Object Select-Object Compare-Object Where-Object Get-WmiObject Get-WinEvent Get-EventLog Group-Object Import-CSV Export-CSV Format-Table Format-List

Getting Help Get-Help <Command> -detailed displays more detailed help -examples will display usage examples -full displays everything, including detailed help, per-parameter help, and usage examples About pages Get-Help about_<topic> About pages exist at C: \Windows\System32\WindowsPowerShell\v1.0\en-US To find commands issue the Get-Command commandlet Get-Command get-* Get-Command remove-* Get-Command set-* Get-Command * Get-Command * where {$_.CommandType -eq "cmdlet"} Get-Help alias is help

Variables The special '$' character is used to notify the shell of a variable Variables can contain text, objects, integers, or a collection of objects. Variables are stored in the PSDrive 'Variable' Cmdlets available for managing variables New-Variable Get-Variable Remove-Variable Clear-Variable Set-Variable Dir Variable Piped variables pipe their content Piped arrays refer to the current object using $_ Powershell will attempt to convert (coerce) objects into the necessary type You can inform Powershell of type using square brackets

Variable Examples

Get-Member Shows you the members of an object that has been passed into it Shows the type name, the formal and unique name by which the object is known Can view nested objects Aliased to "gm" Can show you static methods and properties of classes Get-Process Get-Member Get-Process gm where {$_.MemberType -eq "Property"} Get-WmiObject Win32_OperatingSystem gm Out-GridView [math] Get-Member -Static

Operators, Pipelines, and Filtering Comparison Operators are used to evaluate "True" or "False" Powershell references each by $True and $False 4 < 14 is False Boy = Girl is Fales 7 7 is True Execute Powershell comparisons from the command line: 4 -lt 10 returns False "Boy" -eq "Girl" returns False 7 -le 7 returns True

More Operators Common Operators -eq : Equal to -ne : Not equal to -le : Less than or equal to -ge : Greater than or equal to -gt : Greater than -lt : Less than -like : Uses wildcards for pattern matching -notlike : Negates the -like -match : Uses regular expressions for pattern matching -notmatch : Negates the -match -contains : Determine elements in a group. Evaluates to Boolean $True or $False ++, -- : Increment / decrement

Pipelines, and Filtering The Where-Object cmdlet removes objects from the pipeline based on specified criteria Where-Object uses $_ to represent the current pipelined object Where-Object is aliased as 'where' Using Where-Object can be computationally expensive due to the need to process each object

Quotes, Brackets, and other Punctuation Single quotes is a literal string This costs $100 Double quotes is an evaluated string $what = $100 ; This costs $what Back ticks used as the escape character This is ` quite` a string ; This is on `n two lines Semicolon is the command separator Parentheses are for required parts of control structures and inline execution if (<test1>) {<statement list 1>} $page = (new-object system.net.webclient).downloadstring($url) Braces are for the block expressions in control structures do {<statement list>} until (<condition>) Brackets are used for optional elements [string]typing variables, $indices[0], regular expressions[a-z], and function parameters Double colon is used for calling external methods [System.Math]::Round($Num, 2) Pound is a comment, <#... #> is for block comments

Regular Expressions Powershell provides multiple operators for direct text manipulation -replace -join -split -match Powershell supports industry-standard (Perl) regex syntax to perform pattern matching on strings Use Select-String cmdlet to perform both simple and regular expression matches against text. Analogous to 'grep' in UNIX

Powershell Providers Powershell Providers are.net programs that provide data stores as if they were mounted drives Simplifies access to external data outside the Powershell environment Provides access to data that would not otherwise be easily accessible from the command line View available Providers with Get-PSProvider Use PSDrive to mount Powershell Providers Get-PSDrive

Profiles Profiles in Powershell provide a mechanism to customize the shell environment automatically with each new session Preload modules, custom aliases, connect PSDrives, or anything else that is invoked via a Powershell CLI Powershell searches for a predetermined file in a predetermined location Globally - $PSHome\profile.ps1 User - $Profile\profile.ps1 Powershell profiles will not execute if connected to a remote instance of the shell Powershell profiles will not execute when used within other products Powershell profiles will not execute when execution policy is set to Restricted or if the profile is not signed while the execution policy is set to AllSigned

Powershell Modules Powershell modules are installed in the systemwide module folder C:\Windows\System32\WindowsPowerShell\v1. 0\modules Custom modules can be built per user. They should be installed in the user's home directory C: \Users\<userName>\Documents\WindowsPowerShell\M odules\<modulefoldername>\<custommodule>.psm1 View module search paths with Get-Content env:psmodulepath Modules must be added into the shell to use their functionality. They must remain loaded for the entire shell session while being used. View installed modules with Get-Module -list

Powershell Modules Active Directory Domain Services Active Directory Rights Management Services Applocker Best Practices Analyzer Background Intelligent Transfer Service Group Policy and Group Policy objects Network Load Balancing Windows Powershell Diagnostics Remote Desktop Services Server Manager Server Migration Troubleshooting Packs Web Administration Web Services for Management (WS-MAN) Windows Cluster Service Windows Server Backup

Server Manager Use Server Manager cmdlets to add roles, remove roles, and list roles User Server Manager cmdlets, along with Compare-Object, to provide a change configuration report for role changes on a server Three Server Manager cmdlets exist Get-WindowsFeature Add-WindowsFeature Remove-WindowsFeature Gain access to these cmdlets by importing the SeverManager module Import-Module ServerManager

Powershell and ActiveDirectory ActiveDirectory module is installed when RSAT is installed Includes cmdlets that faciliatate ActiveDirectory administration Its cmdlets provide the functionality that powers the graphical Active Directory Administrative Center Console Adding the ActiveDirectory module also adds a PSDrive It is bad practice to query every object in Active Directory at once Is computationally expensive Can impact Domain Controller's performance Most Active Directory cmdlets have a defined mandatory parameter called '-filter' Find Active Directory cmdlets with 'Get-Command *-AD*'

Powershell and ActiveDirectory Cont.

Powershell Code Signing Get-ExecutionPolicy Get-Help about_signing Execution Policies: Restricted / AllSigned / RemoteSigned / Unrestricted Example Error Message: The file C:\my_script.ps1 cannot be loaded. The execution of scripts is disabled on this system. Please see "Get-Help about_signing" for more details. WolfTech Certificate Services WolfTech Default Execution Policy is "AllSigned" NCSU-Departmental OU Admins can request a code signing cert: You are responsible for the code if you sign it Use-Time cert password required on any script used outside your OU Certs must be published to Trusted Publishers store via GPO Scripts need to be saved as ANSI to be signed PS C:\> Set-AuthenticodeSignature c:\foo.ps1 @(Get-ChildItem cert:\currentuser\my -codesigning)[0]

Powershell ISE PowerShell ISE can run commands, write, test, and debug scripts in a single GUI Provides multiline editing, tab completion, syntax coloring, selective execution, contextsensitive help

MSSQL/Failover Clustering Example Using the SQL Server cmlets Using the SQL Server PowerShell Provider Note: Be Careful of Version (10.0) and Bit level (x86) SQLPS: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlps.exe Add-PSSnapin SqlServerProviderSnapin100 Add-PSSnapin SqlServerCmdletSnapin100 Get-PSSnapin Failover Cluster Cmdlets in Windows PowerShell Move all cluster resources off of "classdemosrv2": Import-Module FailoverClusters Get-ClusterGroup Get-ClusterNode classdemosrv2 Get-ClusterGroup Move-ClusterGroup Get-ClusterResource Sort-Object -Property OwnerGroup

Powershell and VMware Example PowerCLI Powershell API for VMware VCenter Uses a Powershell SnapIn Pipelining and Filtering cd "C:\Program Files (x86)\vmware\infrastructure\vsphere PowerCLI" Add-PSSnapin -Name VMware.VimAutomation.Core.\Scripts\Initialize-PowerCLIEnvironment.ps1

MySQL.Net Example Connector/Net: fully managed ADO.NET driver written in 100% pure C# MySQL Powershell Module MySql.Data.MySqlClient API Reference [void][system.reflection.assembly]::loadfrom("$pwd\mysql.data.dll") Import-Module $pwd\mysql.psm1 $insert = Prepare-MySQL -server 'server' -database 'db' -user 'user' -password 'password' $insert Get-Member If you have a.net library and the API documentation, you can use it in Powershell How do I know if something is using.net? Process Explorer C:\Windows\assembly

AFS Example The Powershell Script for mapping J and K drives has examples of: Looping Conditional Statements Functions Error Checking Accessing AD Balloon Tips

Additional Examples Web Services - Jigsaw:.\DellWebsiteFunctions.ps1 Get-DellWarranty IDKFA Get-WMIObject -Class "Win32_BIOS" -Computer. select SerialNumber DFS/AD Groups - Celerra UI: Forms WMI Explorer SCCM Powershell Module

Where Can I Go for Help? AD Site http://activedirectory.ncsu.edu Mailing Lists activedirectory@lists.ncsu.edu Jabber "activedirectory" on conference.jabber.eos.ncsu.edu Remedy wolftech_ad_technical@remedy.ncsu.edu Governance Committees http://activedirectory.ncsu.edu/governance/

Q & A