Power Shell for Exchange Administrators

download Power Shell for Exchange Administrators

of 38

Transcript of Power Shell for Exchange Administrators

  • 8/2/2019 Power Shell for Exchange Administrators

    1/38

    5/13/20091DejanForodejan.foro@exchangemaster.netSpeaker16yearsofyearsofexperiencewithMStechnologies11yearsand5generationsofexperiencewithExchange(5.5,2000,2003,2007,2010)MCP,MCP+I,MCSENT40,MCSE+I,MCSE2000,MCSE2000:Messaging,MCSA2003,MCSA2003:Messaging,MCSE2003,MCSE2003:Messaging,MCT

  • 8/2/2019 Power Shell for Exchange Administrators

    2/38

    5/13/2009

    SpeakerCommunitiesExchangeUserGroupEurope(founder)SwissITProUserGroupRewardsMCPHallofFame(1of6worldwide)MicrosoftMVP-Exchange(1of120worldwide,theonly1inSwitzerland)MCPSuccessStoriesAgendaIntroductionDoingcommontasksinExchangeUsersrelatedtasksTestingandtroubleshootingSettingupyourownPowerShellenviromentAdditionalresources3rdpartytools,websites,communities,books,webcasts...Q&A

  • 8/2/2019 Power Shell for Exchange Administrators

    3/38

    5/13/2009

    PresentationdowlnoadThispresentationwillbeavailablefordownloadfrom:www.exchangemaster.netIntroductionHowitusedtobe....ProblemsofScriptinginWindowsenviromentManythingscouldbedonethroughcommandlineVBScriptprogrammingknowledgerequired,knowledgeofVB,WMI,WBEM,ADSI,objectmodelssecurityvoulnearable

  • 8/2/2019 Power Shell for Exchange Administrators

    4/38

    5/13/2009

    IntroductionHowitistoday...ScriptingwithPowerShellinExchangeCommandlineinterfacedevelopedfirst,thanGUIEVERYTHINGcanbedoneviacommandlineExchangemanagmentGUIactuallyexecutesPowerShellcommandsandshowsyouthesyntaxSinglelinecommandsreplacepagesofVBcodeSymplesyntaxBettersecurityexectutionofpowershellscriptscompletelydisabledbydefault,requirescriptstobesigned,etc.Example

  • 8/2/2019 Power Shell for Exchange Administrators

    5/38

    5/13/2009

    IntroductionWindowsPowershell-129commandsGet-CommandExchangePowershelladditional394commandsGet-ExcommandDontworry,youwillbecoolwithapprox.20.WhyareyougoingtolovePowerShellTaskexample:Getalistofmailboxesandexportinto.csvfile

  • 8/2/2019 Power Shell for Exchange Administrators

    6/38

    5/13/2009

    WhyyouaregoingtolovePowerShellVBScriptDimSWBemlocatorDimobjWMIServiceDimcolItemsDimobjFSODimobjFilestrTitle="MailboxReport"strComputer=MyServer"UserName=""Password=""strLog="Report.csv"SetobjFSO=CreateObject("Scripting.FileSystemObject")SetobjFile=objFSO.CreateTextFile(strLog,True)strQuery="Select*fromExchange_Mailbox"SetSWBemlocator=CreateObject("WbemScripting.SWbemLocator")SetobjWMIService=SWBemlocator.ConnectServer(strComputer,"\root\MicrosoftExchangeV2",UserName,Password)SetcolItems=objWMIService.ExecQuery(strQuery,,48)

    ForEachobjItemIncolItemsobjFile.writelineobjItem.ServerName&","&objItem.StorageGroupName&_","&objItem.StoreName&","&Chr(34)&objItem.MailboxDisplayNameNextobjFile.closeWhyyouaregoingtolovePowerShellPowerShell.Get-mailbox|export-csvc:\report.csv

  • 8/2/2019 Power Shell for Exchange Administrators

    7/38

    5/13/2009

    ....AndAction!!!CommandSyntaxNew-MailboxGet-MailboxSet-MailboxMove-MailboxRemove-Mailbox...

  • 8/2/2019 Power Shell for Exchange Administrators

    8/38

    5/13/2009

    GettinghelpListofallavailablePowerShellcommandsGet-CommandListofonlyExchangecommandsGet-ExcommandGettinghelpaboutspecificcommandGet-HelpGet-MailboxGet-HelpGet-MailboxdetailedGet-HelpGet-MailboxfullGettinginfoaboutusers/mailboxesListofallmailboxesinorganisationGet-MailboxGet-Mailbox-ResultSizeunlimited

  • 8/2/2019 Power Shell for Exchange Administrators

    9/38

    5/13/2009

    GettingallavailablepropertiesGet-Mailbox|Format-ListGet-MailboxResultSize1|Format-ListGettingjustalistofpropertiesnamesGet-Mailbox|Get-Member-MemberType*Property|Select-ObjectName

  • 8/2/2019 Power Shell for Exchange Administrators

    10/38

    5/13/2009

    Selecting&SortingGet-Mailbox|Select-Object-PropertyDisplayName,PrimarySMTPAddressGet-Mailbox|Select-Object-PropertyDisplayName,PrimarySMTPAddress|Sort-Object-PropertyDisplayNameExamplesListallmailboxes,sortbyname,andexportintoaCSVfileGet-Mailbox|Sort-Object-PropertyName|Export-csvc:\mailboxes.csvGetalistofmailboxesfromActiveDirectoryOUnamedUsersGet-Mailbox-OrganizationalUnitUsers

  • 8/2/2019 Power Shell for Exchange Administrators

    11/38

    5/13/2009

    ExamplesCountmailboxesinorganisation(Get-mailbox).countGettingallpropertiesforaspecificuserGet-Mailbox|where{$_.DisplayName-eq"DejanForo"}|format-listWhoisthepostmaster?Get-Mailbox|where{$_.EmailAddresses-contains"[email protected]"}ExamplesWhoistheuserwithGUIDe65a6ff3-d193-4563-9a8e-26a22315a686?Get-Mailbox|where{$_.guid-eq"e65a6ff3-d193-4563-9a8e-26a22315a686"}WhohasUMextention200?Get-Mailbox|where{$_.extensions-contains"200"}

  • 8/2/2019 Power Shell for Exchange Administrators

    12/38

    5/13/2009

    GettinginfoaboutserversGivemealistofExchangeserversGet-ExchangeserverGet-ExchangeServer|Select-Object-PropertyName,Edition,AdminDisplayVersion,ServerRole|format-listExamplesGivemealistofmailboxserversGet-ExchangeServer|where{$_.ServerRole-ilike"*Mailbox*"}DowehaveserversrunningontrialversionofExchangeandifyeswhendotheyexpire?Get-ExchangeServer|where{$_.IsExchange2007TrialEdition-eq"True"}|Select-Object-PropertyFQDN,RemainingTrialPeriod

  • 8/2/2019 Power Shell for Exchange Administrators

    13/38

    5/13/2009

    GettingmembershipofagroupGet-DistributionGroupMember-identity"SwissITProUserGroupModerators"ManagingtheuserlifecycleCreatingusers-Importingfroma.csvfileModifingusersmovetoanotherdatabaseRemovingmailboxesandusers

  • 8/2/2019 Power Shell for Exchange Administrators

    14/38

    5/13/2009

    Importingusersfroma.CSVfileTaskImportusersfromafilec:\users.csvForeveryuserCreateuseraccountinADofformFirst.Last@exchangemaster.netPuttheminOrganizationalUnitVIPCreateamailboxindatabaseStandardusersEnterhisfirstandlastnameSetalluserswithpasswordPassword123andrequiretheuserstochangethepasswordatfirstlogonImportingusersfroma.CSVfileImport-CSVc:\users.csv

  • 8/2/2019 Power Shell for Exchange Administrators

    15/38

    5/13/2009

    ProcesingvaluesfromacsvfileProcessingeachrowofdatafrom.CSVfileImport-CSVc:\users.csv|ForEach-Object{SOMEACTION}CommandforcreatingUsersNew-MailboxGet-HelpNew-MailboxfullProcessingvaluesfrom.CSVfileReferencingcolumnnamesfromthe.CSVfile$_.columnnameConvertingPasswordtextintosecurestring$Password=ConvertTo-SecureString-String"Password123"-asplaintext-force

  • 8/2/2019 Power Shell for Exchange Administrators

    16/38

    5/13/2009

    Importingusersfroma.CSVfilePuttedalltogether$Password=ConvertTo-SecureString-String"Password123"-asplaintext-forceImport-Csvc:\users.csv|ForEach-Object{$Name=$_.First+""+$_.Last$UPN=$_.First+"."+$_.Last+"@exchangemaster.net"New-Mailbox-Name$Name-UserPrincipalName$UPN-Password$Password-OrganizationalUnitVIP-Database'standardusers'-FirstName$_.First-LastName$_Last-ResetPasswordOnNextLogon$True}MakingchangestousersApplypoliciesAssingtogroupsEnableordisablefeaturesChangingattributesMovingmailboxes....

  • 8/2/2019 Power Shell for Exchange Administrators

    17/38

    5/13/2009

    MovingmailboxesMovingmailoboxesofusersinOUVIPtoanewdatabaseforVIPsGet-Mailbox-OrganizationalUnit"VIP"|Move-Mailbox-TargetDatabase"VIPusers"MovingmailboxesCheckingformailboxlocationaftermoveGet-Mailbox|Select-ObjectName,Database

  • 8/2/2019 Power Shell for Exchange Administrators

    18/38

    5/13/2009

    RemovingmailboxesCheckbeforedeleting!Get-Mailbox-OrganizationalUnitVIP|Remove-Mailbox-WhatIfRemovethemGet-Mailbox-OrganizationalUnitVIP|Remove-MailboxRecommendation3rdpartysnap-inforbettermanipulationofADobjectsQuestSoftwareActiveRolesManagementShellforActiveDirectoy

  • 8/2/2019 Power Shell for Exchange Administrators

    19/38

    5/13/2009

    ManagingqueuesRemovingspammessagesfromthequeueRemove-Message-Filter{FromAddress-like"*spammer.com*}-withNDR$falseTestingGetalistoftestcommandsGet-Commandtest*

  • 8/2/2019 Power Shell for Exchange Administrators

    20/38

    5/13/2009

    TestingScriptexampleReportonExchangedatabasebackupswithPowershellhttp://www.exchangemaster.net/index.php?option=com_content&task=view&id=68&Itemid=57

  • 8/2/2019 Power Shell for Exchange Administrators

    21/38

    5/13/2009

    SettingupyourExchangePowerShelllearningenviromentPrerequisitesSupportedOSMicrosoftWindowsServer2003R2,orMicrosoftWindowsServer2003withSP1orSP2WindowsXPwithServicePack2WindowsVistaWindows2008TheMicrosoft.NETFramework2.0(2.0.50727)PowershellExchange2007SettingupyourExchangePowerShelllearningenviromentAlternativeifyoudontwanttobother:MicrosoftVirtualPCReady-madeMicrosoftVirtualHarddriveExchange2007Exchange2007SP1beta

  • 8/2/2019 Power Shell for Exchange Administrators

    22/38

    5/13/2009

    PowerShellsecurityandcommonproblemsforbeginnersHowdoIrunPowerShellscript?WhenyoutrytorunaPowerShellscriptfromtheRundialogboxorbydoubleclickingit,thescriptdoesnotexecute,butopensinNotepad.Answer:InvokePowerShell.exewithfullpathtoscriptPowerShell.exec:\scripts\MyScript.ps1PowerShellsecurityandcommonproblemsforbeginners

  • 8/2/2019 Power Shell for Exchange Administrators

    23/38

    5/13/2009

    PowerShellsecurityandcommonproblemsforbeginersScriptblockedduetoexecutionpolicyPolicyTypesRestricted,AllSignedRemoteSignedUnrestrictedCommandsGet-ExecutionPolicySet-ExecutionPolicyUnrestrictedSettingtoUnrestrictedisnotrecommendedinproduction!!!PowerShellandCommonproblemsforbeginersProblemscriptwillnotexecuteifcontainsExchangecommandsSolution-createaPowerShellprofilewhichwillloadExchangesnap-insforinstructionssee:FAQ000037-errorwhenexecutingPowerShellscriptwhich

    containsExchangePowerShellcommands

  • 8/2/2019 Power Shell for Exchange Administrators

    24/38

    5/13/2009

    CommunicatingwithuserfromthescriptPromptinguserWrite-Host-ForegroundColorred-BackgroundColoryellow"Formatingyourdrivec:..."Write-Host-ForegroundColorblue-BackgroundColorgreen"BecoolIamjustkidding"GettinguserinputRead-Host3rdpartyeditorsPrimalScript2009Autocomplete,ShowsyousyntaxasyoutypeListofswitchesColorcodingDebuggingScriptsigningwithaonebuttonclickComparingscriptsSourcecontrolFTPtransferCodereusingEtc.

  • 8/2/2019 Power Shell for Exchange Administrators

    25/38

    5/13/2009

    PrimalScriptEditorsandenhancmentsPrimalScripthttp://www.primalscript.com/PowerShellIDEhttp://powershell.de/PowerShellAnalyzerwww.powershellanalyzer.comPowerShellPlushttp://www.powershell.com/plus/

  • 8/2/2019 Power Shell for Exchange Administrators

    26/38

    5/13/2009

    IdontlikecomandlineAlternativestoPowerShellPowerGUIhttp://www.powergui.org/index.jspaADInfinitumhttp://www.newfawm.com/adi2.htmScriptlogichttp://www.scriptlogic.com/PowerGUI

  • 8/2/2019 Power Shell for Exchange Administrators

    27/38

    5/13/2009

    PowerGUIPowerGUI

  • 8/2/2019 Power Shell for Exchange Administrators

    28/38

    5/13/2009

    PowerGUIAdditionalExchangeresourcesMicrosoftExchangeserverwebsitehttp://www.microsoft.com/exchangeMicrosoftExchangeTeamBlog(YouhadmeatEHLO)http://msexchangeteam.comTechnetMicrosoftExchangeServerTechCenterhttp://www.microsoft.com/technet/prodtechnol/exchange/default.mspxVirtuallabshttp://www.microsoft.com/technet/prodtechnol/exchange/virtuallab/default.mspxWebcastshttp://www.microsoft.com/technet/prodtechnol/exchange/2007/webcasts.mspx

  • 8/2/2019 Power Shell for Exchange Administrators

    29/38

    5/13/2009

    PowerShellbooksLiteFrankKoch,MicrosoftSwitzerlandGermanversionEnglishversionPowerShellbooksmediumPowerShelldocumentationPackManualsthatcomeswithPowershellhttp://www.microsoft.com/downloads/details.aspx?FamilyID=b4720b00-9a66-430f-bd56-ec48bfca154f&DisplayLang=en

  • 8/2/2019 Power Shell for Exchange Administrators

    30/38

    5/13/2009

    PowershellBooksAdvancedConvertingVBScriptCommandstoWindowsPowerShellCommandshttp://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/default.mspx

  • 8/2/2019 Power Shell for Exchange Administrators

    31/38

    5/13/2009

    WebcastsinGermanKlickstDunochoderskriptestDuschon?FrankRderMVPWindowsServerSystem-DirectoryServicesTeil1WindowsPowerShellEinfhrungTeil2Server-AdministrationmitWindowsPowerShellTeil3ExchangeServer2007AdministrationmitWindowsPowerShellWebsitesandblogsWindowsPowerShellHomehttp://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspxBlogofWindowsPowershellteamhttp://Blogs.msdn.com/powershellTheMicrosoftExchangeTeamblog:http://msexchangeteam.com/default.aspxVivekSharmasblog:http://www.viveksharma.com/techlog/category/scripts/ThePowerShellGuyhttp://thepowershellguy.com/blogs/posh/pages/powertab.aspx

  • 8/2/2019 Power Shell for Exchange Administrators

    32/38

    5/13/2009

    WebsitesandblogsGlenScalesdevelopmentbloghttp://gsexdev.blogspot.com/WebcastsIntroductiontoWindowsPowerShellScriptinginExchangeServer2007(Level200)TechNetWebcast:24HoursofExchangeServer2007(Part09of24):UsingPowerShellforExchangeManagement(Level200)MicrosoftWindowsPowerShellScriptingforMicrosoftExchangeServer2007(Level300)

  • 8/2/2019 Power Shell for Exchange Administrators

    33/38

    5/13/2009

    CommunityPowerShellAnwendergruppewww.powershell-ag.deCommunityPowerShellLiveGet-Community|Where{$_.passion-eq"PowerShell}http://powershelllive.com

  • 8/2/2019 Power Shell for Exchange Administrators

    34/38

    5/13/2009

    CommunitySwissITProusergroupwww.swisitpro.chExchangeUserGroupEuropehttp://www.eugeurope.orgSpeakerswantedGet-speaker|where{$._passioneqcommnunity}[email protected]

  • 8/2/2019 Power Shell for Exchange Administrators

    35/38

    5/13/2009

    Questions?QuestionsandAnswersQ-CanpowershellbeusedagainstExchange2003machines?Ayes,butnotwithallfunctionalityandlooksuglyhttp://blog.sapien.com/current/2007/2/21/managing-exchange-2003-servers-with-powershell.html

  • 8/2/2019 Power Shell for Exchange Administrators

    36/38

    5/13/2009

    QuestionsandAnswersQCanPowerShellbeusedfrom.NETLanguageslikeIronPhyton?APowerShellisbasedon.NETframeworkandthereforecanbeembededinother.NETlanguagesandviceversa.Herearesomeexamples:UsingIronPythonfromPowerShellPart1:WatchfolderforchangeswithoutblockingConsolehttp://thepowershellguy.com/blogs/posh/archive/2007/02/10/using-ironpython-from-powershell-part-1-watch-folder-for-changes-without-blocking-console.aspxEmbeddingPowerShellinIronPythonandviceversa--twogreattastesthattastegreattogetherhttp://stevegilham.blogspot.com/2008/02/embedding-powershell-in-ironpython.htmlPresentationdowlnoadThispresentationwillbeavailablefordownloadfrom:www.exchangemaster.net

  • 8/2/2019 Power Shell for Exchange Administrators

    37/38

    5/13/2009

    Contact:E-mail:[email protected]:http://www.linkedin.com/in/dejanforoXing(OpenBC):http://www.xing.com/profile/Dejan_Foro

  • 8/2/2019 Power Shell for Exchange Administrators

    38/38