console quick script functions advanced functions modules console quick script functions advanced...

Post on 03-Jan-2016

271 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Shane HoeyLync MVP

Powershell Boot Camp

SERV306

I Speak Australianhttp://bit.ly/

KbeCIW

AgendaDiving head first into Powershell…Core features & discoverability.Lync focused demos.

Key takeawaysGain better understanding of using Windows PowerShell.Improve management of your Lync Server environment with Windows PowerShell.

Where are we going ?

Console Quick Script

Functions

Advanced

Functions

ModulesConsole Quick Script

Functions

Advanced

Functions

Modules

Why PowerShell?

Lync 2013 and PowerShell put you in Control with a single management interface for delivering universal communications across the enterprise, from robust server deployments to cost-effective online services.

Choose the right tool for the job

Verb-Noun <Parameters><Common Parameters>get-service -name wuauserv -requiredservices –erroraction

continue

Cmdlets

All you really need to knowGet-Help

Displays information about Windows PowerShell concepts and commands.

This includes cmdlets, functions, CIM commands, workflows, providers, aliases and scripts.

Includes Conceptual help topics: get-help about_PowerShell.exe.

Supports scripts and modules.

get-help get-help

All you really need to knowGet-Command

Output comes directly from the actual command’s code unlike Get-Help which come’s from Help Topics.

Includes cmdlets, aliases, functions, workflows, filters, scripts, and applications.

Useful to confirm the output type.

get-help get-command

All you really need to knowGet-Member

Gets the "members" (properties and methods)of objects.

You just really need to know and use this cmdlet!

get-help get-member

All you really need to knowShow-Command (v3)GUI tool to help build command. Built into the PowerShell ISE.

Update-Help (v3) No help by default, so we use update-help.Does require administrator privileges.Not all cultures supported, so try EN-US instead.Not all modules support updateable help.

get-help about_updatable_help

get-serviceObjectType:

System.ServiceProcess.ServiceController

Properties:• Name• Status• CanStop

Methods:• Start()• Stop()• Pause()

Objectsget-service

ObjectType: System.ServiceProcess.ServiceController

Properties:• Name• Status• CanStop

Methods:• Start()• Stop()• Pause()

get-serviceObjectType:

System.ServiceProcess.ServiceController

Properties:• Name• Status• CanStop

Methods:• Start()• Stop()• Pause()

get-help about_objects

Pipeline, the basics

get-service sort -descselect –first

10 format-list

get-help about_pipelines

Pipeline, objects do change

get-service sort -desc select –first 10

format-list

get-help about_pipelines

Pipeline ByValue

get-service stop-service

Output TypeSystem.ServiceProcess.ServiceControlle

r

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Input ObjectSystem.ServiceProcess.ServiceController

PropertiesProperty: -ID <int32>

Property: -Name <string>

Output TypeSystem.ServiceProcess.ServiceCont

roller

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Input ObjectSystem.ServiceProcess.ServiceControlle

r

PropertiesProperty: -ID <int32>

Property: -Name <string>

Input ObjectSystem.ServiceProcess.ServiceControlle

r

PropertiesProperty: -ID <int32>

Property: -Name <string>

Output TypeSystem.ServiceProcess.ServiceCont

roller

PropertiesProperty: -NameProperty: -StatusProperty: -Display

get-help about_pipelines

Pipeline ByPropertyName

get-service stop-process

Output TypeSystem.ServiceProcess.ServiceControlle

r

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Input ObjectSystem.Diagnostics.Process

PropertiesProperty: -ID <int32>

Property: -Name <string>

Output TypeSystem.ServiceProcess.ServiceCont

roller

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Input ObjectSystem.Diagnostics.Process

PropertiesProperty: -ID <int32>

Property: -Name <string>

Input ObjectSystem.Diagnostics.Process

PropertiesProperty: -ID <int32>

Property: -Name <string>

Output TypeSystem.ServiceProcess.ServiceCont

roller

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Output TypeSystem.ServiceProcess.ServiceCont

roller

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Input ObjectSystem.Diagnostics.Process

PropertiesProperty: -ID <int32>

Property: -Name <string>

Output TypeSystem.ServiceProcess.ServiceCont

roller

PropertiesProperty: -NameProperty: -StatusProperty: -Display

Input ObjectSystem.Diagnostics.Process

PropertiesProperty: -ID <int32>

Property: -Name <string>

get-help about_pipelines

Pipeline, Filter Left, Format Right

get-servicewhere

name –like s*format-list

Pipeline, Filter Left, Format Right

get-service-name s* format-list

Parentheses, not Pipeline

get-service –computername (get-content servers.txt)get-service –computername server1,server2

foreach, not Pipeline - v4 alert

(“server1”,”server2”).foreach({get-service –computername $_})

Variables

$myvariable = “LyncConf14”[string]$myvariable = “LyncConf14”

get-help about_arrays

get-service –outvariable myvariable

Arrays

$myarray = 1,2,3,4,5$myusers = Get-csuser$myarray = @()$myarray = ,1$myarray is [array]

get-help about_arrays

Enumerating Arrays

Foreach ($item in $myarray) { $item}$myarray[0]

get-help about_arrays

$myarray[3..7]$myarray[-1]

Managing Arrays

$myarray += 67

get-help about_arrays

$myarray[2] = 67$myarray = $myarray[0..2 + 4..($myarray.length – 1 )]

Hash Tables

@{key=Value;Key2=value2;Key3=value3}$hash = @ { }$hash = @ { “computername”

=“localhost”;“model”=“Surface”}

get-help about_hash_tables

$hash.Add(“IPAddress", $ipaddress) $hash.remove(“IPAddress")

PowerShell Demos

#requires –version 4.0<#Lync 2013#>

Start-Demo.ps1

Best Practices with PowerShell

Read the Help, Update the HelpFocus on the objectUse the pipelineFilter Left, Format RightUse Meaningful variable names, and type

Best Practices with PowerShell

Think about Code Reuse, return objectsUse verb-noun naming standard for scripts/functionsNo Aliases in scriptsUse Full Parameter names in scripts

Best Practices with PowerShell

$ErrorActionPreferences = ‘SilentlyContinue’Use –erroraction parameter instead

Don’t reinvent the wheel -> but always check what you are running !Never run first in Production, and Test , Test, Test >Don’t write-host

Please don’t Write-HostUse these cmdlets insteadDisplay formatted help use comment based helpDisplay Progress write-progressVerbose Information write-verboseDebugging information write-debugDisplay a warning write-warningDisplay an error use write-error

If you must use write-host,It’s important to rememberit changes the object

Career Limiting Scriptsget-aduser -filter * | remove-aduser –force

Get-CsBlockedDomain -Filter *domain* | Remove-CsBlockedDomain

$userpath = $aduser.samaccountname$fullpath = "\\Servername\fileshare\" + $userpath Cmd /C "rmdir /S /Q $userpath“

RecapUse Powershell the way its been designed: Get-help Get-commandGet-member

PowerShell is EverywhereEverything you can do in the GUI you can do in PowerShell

Additional SessionsSERV204 Dive Deep - Lync Server 201x Management using PowerShell and MoreONLI300 Remote PowerShell and Reporting

Final Thought….

Failing to learn PowerShell is career limiting, It’s not scary, It’s easy to learn, and It’s

Everywhere, And best of all…

PowerShell is PowerShell is PowerShell.Learn it Once, Use it Everywhere.

@shanehoeyshane@lyncitpro.com

Questions ?

Microsoft PavilionDemos, Speakers, Demos, Lync Room System, Experts, Demos, a Bar....and more Demos

ATTENDEE PARTYWednesday, February 19th

6:30pm-9:30pmHakkasan, MGM Grand

Brought to you by

When it comes to Vegas nightclubs, it doesn’t get any hotter than Hakkasan. And when it comes to opportunities to connect and reasons to party, no one does it better than Lync Conference! Our attendee party has a full lineup: an open bar, awesome food, and one of the best DJs that Vegas has to offer. Don’t miss out on the fun—stop by at 6:30pm and kick off and evening to remember. Come together.

HANDS-ON LABS

You can also access labs on MyLync!

3:00pm – 9:00pm10:30am – 9:00pm7:30am – 9:00pm8:00am –1:30pm

LOCATIONPinyon 3

Monday, February 17Tuesday, February 18Wednesday, February 19 Thursday, February 20

LRS

LOCATIONCopperleaf 12

Wednesday, February 198:30am – 9:45am10:15am – 11:30am1:00pm – 2:15pm2:45pm – 4:00pm4:30pm – 5:45pm

Thursday, February 209:00am – 10:15am10:45am – 12:15pm12:45pm – 2:00pm

MyLync allows you to create a custom experience and network with the Lync Community both online and in person.With MyLync, you can:• Build your own personalized calendar while browsing all available sessions• View breakout session material including PPTs and Videos within

48 hours of each session• Participate in the Community and find people in your social networks

who are attending and interact with speakers• Arrange meetings or social activities• Navigate the Exhibit Hall floor plan and learn more about our Sponsors• Fill out evaluations to win prizes

Log into MyLync at http://mylync.lyncconf.comFor MyLync support, please visit the Registration Desk.*

* Please note that adding a session to your calendar does not reserve a seat. Seating is on a first-come, first-served basis.

Birds of a FeatherBirds of a Feather flock together! Join daily breakfast discussions of relevant topics by sitting in the separately designated areas of the Meal Hall. Seating will be sorted in a different way for each Birds of a Feather breakfast:Wednesday, February 19:Where are you from? Asia/Pacific, Eastern & Central Europe, Latin America, Middle East & Africa, US (West, Central & East) and Canada, Western Europe

Thursday, February 20:What is your interest?Best Practices, Business Value, Clients & Mobility, Lync Meetings and Video, Lync Online, Networking, Platform, Server & Manageability, Voice

Fill out evaluations to win prizesFill out evaluations on MyLync or MyLync Mobile.Prizes awarded daily.

© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

top related