5/13/2009. Dejan Foro Speaker

37 

Loading....

Loading....

Loading....

Loading....

Loading....

Full text

(1)5/13/2009. Dejan Foro dejan.foro@exchangemaster.net. Speaker  16 years of years of experience with MS. technologies  11 years and 5 generations of experience with Exchange (5.5, 2000, 2003, 2007, 2010)  MCP, MCP+I, MCSE NT40, MCSE+I, MCSE 2000, MCSE 2000:Messaging, MCSA 2003, MCSA 2003:Messaging, MCSE 2003, MCSE 2003:Messaging, MCT. 1.

(2) 5/13/2009. Speaker  Communities  Exchange User Group Europe (founder)  Swiss IT Pro User Group  Rewards  MCP Hall of Fame . (1 of 6 worldwide).  Microsoft MVP - Exchange . (1 of 120 worldwide, the only 1 in Switzerland).  MCP Success Stories. Agenda  Introduction  Doing common tasks in Exchange  Users related tasks  Testing and troubleshooting  Setting up your own PowerShell enviroment  Additional resources  3rd party tools, web sites, communities, books, webcasts...  Q&A. 2.

(3) 5/13/2009. Presentation dowlnoad  This presentation will be available for download. from:. www.exchangemaster.net. Introduction  How it used to be ....  Problems of Scripting in Windows enviroment  . . Many things could be done through command line VBScript – programming knowledge required, knowledge of VB, WMI, WBEM, ADSI, object models security voulnearable. 3.

(4) 5/13/2009. Introduction  How it is today ...  Scripting with PowerShell in Exchange   .   . Command line interface developed first, than GUI EVERYTHING can be done via command line Exchange managment GUI actually executes PowerShell commands and shows you the syntax Single line commands replace pages of VB code Symple syntax Better security – exectution of powershell scripts completely disabled by default, require scripts to be signed, etc.. Example. 4.

(5) 5/13/2009. Introduction  Windows Powershell - 129 commands Get-Command  Exchange Powershell – additional 394 commands Get-Excommand  Don’t worry, you will be cool with approx. 20 ☺. Why are you going to love PowerShell  Task example :  Get a list of mailboxes and export into .csv file. 5.

(6) 5/13/2009. Why you are going to love PowerShell  VBScript  Dim SWBemlocator Dim objWMIService Dim colItems Dim objFSO Dim objFile strTitle="Mailbox Report" strComputer = “MyServer" UserName = "" Password = "" strLog="Report.csv" Set objFSO=CreateObject("Scripting.FileSystemObject") Set objFile=objFSO.CreateTextFile(strLog,True) strQuery="Select * from Exchange_Mailbox" Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = SWBemlocator.ConnectServer(strComputer,"\root\MicrosoftExchangeV2",UserName,Password) Set colItems = objWMIService.ExecQuery(strQuery,,48) For Each objItem In colItems objFile.writeline objItem.ServerName & "," &objItem.StorageGroupName &_ "," & objItem.StoreName & "," & Chr(34) & objItem.MailboxDisplayName Next objFile.close. Why you are going to love PowerShell  PowerShell ☺. Get-mailbox | export-csv c:\report.csv. 6.

(7) 5/13/2009. .... And Action !!!. Command Syntax  New-Mailbox  Get-Mailbox  Set-Mailbox  Move-Mailbox  Remove-Mailbox .... 7.

(8) 5/13/2009. Getting help  List of all available PowerShell commands Get-Command  List of only Exchange commands Get-Excommand  Getting help about specific command Get-Help Get-Mailbox Get-Help Get-Mailbox – detailed Get-Help Get-Mailbox – full. Getting info about users/mailboxes  List of all mailboxes in organisation Get-Mailbox Get-Mailbox -ResultSize unlimited. 8.

(9) 5/13/2009. Getting all available properties Get-Mailbox | Format-List Get-Mailbox –ResultSize 1 | Format-List. Getting just a list of properties names Get-Mailbox | Get-Member -MemberType *Property | Select-Object Name. 9.

(10) 5/13/2009. Selecting & Sorting Get-Mailbox | Select-Object -Property DisplayName, PrimarySMTPAddress. Get-Mailbox | Select-Object -Property DisplayName, PrimarySMTPAddress | Sort-Object -Property DisplayName. Examples • List all mailboxes, sort by name, and export into a CSV file Get-Mailbox | Sort-Object -Property Name | Export-csv c:\mailboxes.csv. • Get a list of mailboxes from Active Directory OU named Users Get-Mailbox -OrganizationalUnit Users. 10.

(11) 5/13/2009. Examples • Count mailboxes in organisation (Get-mailbox).count.  Getting all properties for a specific user Get-Mailbox | where {$_.DisplayName -eq "Dejan Foro"} | format-list  Who is the postmaster ? Get-Mailbox | where {$_.EmailAddresses contains "postmaster@exchangemaster.net"}. Examples  Who is the user with GUID e65a6ff3-d193-4563-9a8e26a22315a686 ? Get-Mailbox | where {$_.guid -eq "e65a6ff3-d193-4563-9a8e-26a22315a686"}  Who has UM extention 200 ? Get-Mailbox | where {$_.extensions contains "200"}. 11.

(12) 5/13/2009. Getting info about servers  Give me a list of Exchange servers Get-Exchangeserver. Get-ExchangeServer | Select-Object -Property Name, Edition, AdminDisplayVersion, ServerRole | format-list. Examples  Give me a list of mailbox servers Get-ExchangeServer | where {$_.ServerRole -ilike "*Mailbox*"}.  Do we have servers running on trial version of Exchange and if yes when do they expire ? Get-ExchangeServer | where {$_.IsExchange2007TrialEdition -eq "True"} | Select-Object -Property FQDN, RemainingTrialPeriod. 12.

(13) 5/13/2009. Getting membership of a group Get-DistributionGroupMember -identity "Swiss IT Pro User Group Moderators". Managing the user lifecycle  Creating users - Importing from a .csv file  Modifing users – move to another database  Removing mailboxes and users. 13.

(14) 5/13/2009. Importing users from a .CSV file  Task  Import users from a file c:\users.csv  For every user .    . Create user account in AD of form First.Last@exchangemaster.net Put them in Organizational Unit VIP Create a mailbox in database “Standard users” Enter his first and last name Set all users with password Password123 and require the users to change the password at first logon. Importing users from a .CSV file. Import-CSV c:\users.csv. 14.

(15) 5/13/2009. Procesing values from a csv file  Processing each row of data from .CSV file Import-CSV c:\users.csv | ForEach-Object { SOME ACTION}  Command for creating Users New-Mailbox Get-Help New-Mailbox –full. Processing values from .CSV file  Referencing column names from the .CSV file $_.columnname  Converting Password text into secure string $Password = ConvertTo-SecureString String "Password123" -asplaintext -force. 15.

(16) 5/13/2009. Importing users from a .CSV file  Putted all together $Password = ConvertTo-SecureString -String "Password123" asplaintext -force Import-Csv c:\users.csv | ForEach-Object { $Name = $_.First + " " + $_.Last $UPN = $_.First + "." + $_.Last + "@exchangemaster.net" New-Mailbox -Name $Name -UserPrincipalName $UPN -Password $Password -OrganizationalUnit VIP -Database 'standard users' FirstName $_.First -LastName $_Last -ResetPasswordOnNextLogon $True}. Making changes to users  Apply policies  Assing to groups  Enable or disable features  Changing attributes  Moving mailboxes ..... 16.

(17) 5/13/2009. Moving mailboxes  Moving mailoboxes of users in OU VIP to a new database for VIPs Get-Mailbox -OrganizationalUnit "VIP" | Move-Mailbox -TargetDatabase "VIP users". Moving mailboxes  Checking for mailbox location after move Get-Mailbox | Select-Object Name,Database. 17.

(18) 5/13/2009. Removing mailboxes  Check before deleting ! Get-Mailbox -OrganizationalUnit VIP | Remove-Mailbox -WhatIf  Remove them Get-Mailbox -OrganizationalUnit VIP | Remove-Mailbox. Recommendation  3rd party snap-in for better manipulation of ADobjects  Quest Software . ActiveRoles Management Shell for Active Directoy. 18.

(19) 5/13/2009. Managing queues  Removing spam messages from the queue Remove-Message -Filter {FromAddress -like "*spammer.com*“ } -withNDR $false. Testing  Get a list of test commands  Get-Command test*. 19.

(20) 5/13/2009. Testing. Script example  Report on Exchange database backups with Powershell http://www.exchangemaster.net/index.php?option=com_conte nt&task=view&id=68&Itemid=57. 20.

(21) 5/13/2009. Setting up your Exchange PowerShell learning enviroment  Prerequisites  Supported OS     . Microsoft Windows Server 2003 R2, or Microsoft Windows Server 2003 with SP1 or SP2 Windows XP with Service Pack 2 Windows Vista Windows 2008.  The Microsoft .NET Framework 2.0 (2.0.50727).  Powershell  Exchange 2007. Setting up your Exchange PowerShell learning enviroment  Alternative if you don’t want to bother:  Microsoft Virtual PC  Ready-made Microsoft Virtual Hard drive  . Exchange 2007 Exchange 2007 SP1 beta. 21.

(22) 5/13/2009. PowerShell security and common problems for beginners  How do I run PowerShell script? . When you try to run a PowerShell script from the Run dialog box or by double clicking it, the script does not execute, but opens in Notepad..  Answer:  Invoke PowerShell.exe with full path to script PowerShell.exe c:\scripts\MyScript.ps1. PowerShell security and common problems for beginners. 22.

(23) 5/13/2009. PowerShell security and common problems for beginers  Script blocked due to execution policy  Policy Types  Restricted,  AllSigned  RemoteSigned  Unrestricted  Commands Get-ExecutionPolicy Set-ExecutionPolicy Unrestricted.  Setting to Unrestricted is not recommended in production. !!!. PowerShell and Common problems for beginers  Problem – script will not execute if contains Exchange commands  Solution - create a PowerShell profile which will load Exchange snap-ins  for instructions see: FAQ 000037 - error when executing PowerShell script which contains Exchange PowerShell commands. 23.

(24) 5/13/2009. Communicating with user from the script  Prompting user Write-Host -ForegroundColor red -BackgroundColor yellow "Formating your drive c: ..." Write-Host -ForegroundColor blue -BackgroundColor green "Be cool I am just kidding".  Getting user input Read-Host. 3rd party editors  Primal Script 2009  Autocomplete,  Shows you syntax as you type  List of switches  Color coding  Debugging  Script signing with a one button click  Comparing scripts  Source control  FTP transfer  Code reusing  Etc.. 24.

(25) 5/13/2009. Primal Script. Editors and enhancments  Primal Script http://www.primalscript.com/  PowerShell IDE http://powershell.de/  PowerShell Analyzer www.powershellanalyzer.com  PowerShell Plus http://www.powershell.com/plus/. 25.

(26) 5/13/2009. I don’t like comand line   Alternatives to PowerShell  Power GUI http://www.powergui.org/index.jspa  AD Infinitum. http://www.newfawm.com/adi2.htm  Scriptlogic. http://www.scriptlogic.com/. PowerGUI. 26.

(27) 5/13/2009. PowerGUI. PowerGUI. 27.

(28) 5/13/2009. PowerGUI. Additional Exchange resources  Microsoft  Exchange server web site . http://www.microsoft.com/exchange.  Microsoft Exchange Team Blog (You had me at EHLO) . http://msexchangeteam.com.  Technet –Microsoft Exchange Server TechCenter . http://www.microsoft.com/technet/prodtechnol/exchange/defa ult.mspx.  Virtual labs . http://www.microsoft.com/technet/prodtechnol/exchange/virtu allab/default.mspx.  Webcasts . http://www.microsoft.com/technet/prodtechnol/exchange/2007 /webcasts.mspx. 28.

(29) 5/13/2009. PowerShell books – Lite  Frank Koch, Microsoft Switzerland  German version  English version. PowerShell books – medium  PowerShell documentation Pack  Manuals that comes with Powershell http://www.microsoft.com/downloads/details.aspx?Famil yID=b4720b00-9a66-430f-bd56ec48bfca154f&DisplayLang=en. 29.

(30) 5/13/2009. Powershell Books – Advanced. Converting VBScript Commands to Windows PowerShell Commands. http://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/default. mspx. 30.

(31) 5/13/2009. Webcasts – in German  Klickst Du noch oder skriptest Du schon?  Frank Röder MVP Windows Server System - Directory Services  Teil 1 Windows PowerShell Einführung  Teil 2 Server-Administration mit Windows PowerShell  Teil 3 Exchange Server 2007 Administration mit Windows PowerShell. Websites and blogs  Windows PowerShell Home. http://www.microsoft.com/windowsserver2003/technologies/management/po wershell/default.mspx.  Blog of Windows Powershell team http://Blogs.msdn.com/powershell  The Microsoft Exchange Team blog: http://msexchangeteam.com/default.aspx  Vivek Sharma’s blog: http://www.viveksharma.com/techlog/category/scripts/  The PowerShell Guy http://thepowershellguy.com/blogs/posh/pages/powertab.aspx. 31.

(32) 5/13/2009. Websites and blogs Glen Scales development blog.  http://gsexdev.blogspot.com/. Webcasts  Introduction to Windows PowerShell Scripting in Exchange Server 2007 (Level 200)  TechNet Webcast: 24 Hours of Exchange Server 2007 (Part 09 of 24): Using PowerShell for Exchange Management (Level 200)  Microsoft Windows PowerShell Scripting for Microsoft Exchange Server 2007 (Level 300). 32.

(33) 5/13/2009. Community • PowerShell Anwendergruppe www.powershell-ag.de. Community  PowerShell Live Get-Community | Where {$_.passion -eq "PowerShell”}.  http://powershelllive.com. 33.

(34) 5/13/2009. Community  Swiss IT Pro user group  www.swisitpro.ch.  Exchange User Group Europe  http://www.eugeurope.org. Speakers wanted  Get-speaker | where {$._passion –eq “commnunity”}. Contact dejan.foro@eugeurope.org. 34.

(35) 5/13/2009. Questions ?. Questions and Answers  Q - Can powershell be used against Exchange 2003 machines ?  A – yes, but not with all functionality and looks ugly http://blog.sapien.com/current/2007/2/21/managingexchange-2003-servers-with-powershell.html. 35.

(36) 5/13/2009. Questions and Answers  Q – Can PowerShell be used from .NET Languages like. IronPhyton ?  A – PowerShell is based on .NET framework and therefore can be embeded in other .NET languages and vice versa. Here are some examples:  Using IronPython from PowerShell Part 1 : Watch folder for changes. without blocking Console http://thepowershellguy.com/blogs/posh/archive/2007/02/10/usingironpython-from-powershell-part-1-watch-folder-for-changeswithout-blocking-console.aspx  Embedding PowerShell in IronPython and vice versa -- “two great tastes that taste great together” http://stevegilham.blogspot.com/2008/02/embedding-powershellin-ironpython.html. Presentation dowlnoad  This presentation will be available for download. from: www.exchangemaster.net. 36.

(37) 5/13/2009. Contact:  E-mail: dejan.foro@exchangemaster.net  LinkedIn: http://www.linkedin.com/in/dejanforo  Xing (OpenBC): http://www.xing.com/profile/Dejan_Foro. 37.

(38)

Figure

Updating...

References

Updating...