Posts RSS Comments RSS 117 Posts and 170 Comments till now

Exchange: Get-User (Return Info)

  1.  
  2.  
  3.    TypeName: Microsoft.Exchange.Data.Directory.Management.User
  4.  
  5. Name                     MemberType Definition
  6. —-                     ———- ———-
  7. AllowUMCallsFromNonUsers Property   Microsoft.Exchange.Data.Directory.Recipient.AllowUMCallsFromNonUsersFlags AllowU…
  8. AssistantName            Property   System.String AssistantName {get;set;}
  9. City                     Property   System.String City {get;set;}
  10. Company                  Property   System.String Company {get;set;}
  11. CountryOrRegion          Property   Microsoft.Exchange.Data.Directory.CountryInfo CountryOrRegion {get;set;}
  12. Department               Property   System.String Department {get;set;}
  13. DirectReports            Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[Microsoft.Exchange.Data.Directory
  14. DisplayName              Property   System.String DisplayName {get;set;}
  15. DistinguishedName        Property   System.String DistinguishedName {get;}
  16. ExchangeVersion          Property   Microsoft.Exchange.Data.ExchangeObjectVersion ExchangeVersion {get;}
  17. Fax                      Property   System.String Fax {get;set;}
  18. FirstName                Property   System.String FirstName {get;set;}
  19. Guid                     Property   System.Guid Guid {get;}
  20. HomePhone                Property   System.String HomePhone {get;set;}
  21. Identity                 Property   Microsoft.Exchange.Data.ObjectId Identity {get;}
  22. Initials                 Property   System.String Initials {get;set;}
  23. IsSecurityPrincipal      Property   System.Boolean IsSecurityPrincipal {get;}
  24. IsValid                  Property   System.Boolean IsValid {get;}
  25. LastName                 Property   System.String LastName {get;set;}
  26. Manager                  Property   Microsoft.Exchange.Data.Directory.ADObjectId Manager {get;set;}
  27. MobilePhone              Property   System.String MobilePhone {get;set;}
  28. Name                     Property   System.String Name {get;set;}
  29. Notes                    Property   System.String Notes {get;set;}
  30. ObjectCategory           Property   Microsoft.Exchange.Data.Directory.ADObjectId ObjectCategory {get;}
  31. ObjectClass              Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Version=…
  32. Office                   Property   System.String Office {get;set;}
  33. OriginatingServer        Property   System.String OriginatingServer {get;}
  34. OtherFax                 Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Version=…
  35. OtherHomePhone           Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Version=…
  36. OtherTelephone           Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Version=…
  37. Pager                    Property   System.String Pager {get;set;}
  38. Phone                    Property   System.String Phone {get;set;}
  39. PhoneticDisplayName      Property   System.String PhoneticDisplayName {get;set;}
  40. PostalCode               Property   System.String PostalCode {get;set;}
  41. PostOfficeBox            Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Version=…
  42. RecipientType            Property   Microsoft.Exchange.Data.Directory.Recipient.RecipientType RecipientType {get;}
  43. RecipientTypeDetails     Property   Microsoft.Exchange.Data.Directory.Recipient.RecipientTypeDetails RecipientTypeDe…
  44. ResetPasswordOnNextLogon Property   System.Boolean ResetPasswordOnNextLogon {get;set;}
  45. SamAccountName           Property   System.String SamAccountName {get;set;}
  46. Sid                      Property   System.Security.Principal.SecurityIdentifier Sid {get;}
  47. SidHistory               Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.Security.Principal.Securit
  48. SimpleDisplayName        Property   System.String SimpleDisplayName {get;set;}
  49. StateOrProvince          Property   System.String StateOrProvince {get;set;}
  50. StreetAddress            Property   System.String StreetAddress {get;set;}
  51. TelephoneAssistant       Property   System.String TelephoneAssistant {get;set;}
  52. Title                    Property   System.String Title {get;set;}
  53. UMDialPlan               Property   Microsoft.Exchange.Data.Directory.ADObjectId UMDialPlan {get;set;}
  54. UMDtmfMap                Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Version=…
  55. UserPrincipalName        Property   System.String UserPrincipalName {get;set;}
  56. WebPage                  Property   System.String WebPage {get;set;}
  57. WhenChanged              Property   System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, …
  58. WhenCreated              Property   System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, …
  59. WindowsEmailAddress      Property   Microsoft.Exchange.Data.SmtpAddress WindowsEmailAddress {get;set;}

Powershell Crushes VBScript with AD query again

In my on going battle on EE to prove the value of powershell, I have destroyed yet another vbscript. While the vbscript look was impressive it was a monsterous 38 lines compaired to Powershell 12. Again with no short-cuts, you could trim another 4 lines with ease.

Here is my code. It gets all the groups and list the group name / member count / OU.

  1. $filter = "(&(objectcategory=group))"
  2. $root = [ADSI]""
  3. $dsSearcher = new-Object System.DirectoryServices.DirectorySearcher($root,$filter)
  4. $dsSearcher.PageSize = 1000
  5. $groups = $dsSearcher.findAll()
  6. @(foreach($group in $groups)
  7. {
  8.     [string]$name = $group.Properties.cn
  9.     [string]$count = ($group.psbase.properties.member).count
  10.     [string]$OU = ((($group.GetDirectoryEntry()).psbase).parent).distinguishedName
  11.     "GROUP:{0} Count:{1} OU:{2}" -f $name.PadRight(35),$count.padright(5),$ou
  12. }) | out-file C:\temp\yourfile.txt -enc ASCII

Output looks like this
GROUP:TGroup1 Count: OU:OU=MyGroups,DC=corp,DC=bb,DC=lab
GROUP:TGroup2 Count: OU:OU=MyGroups,DC=corp,DC=bb,DC=lab
GROUP:TGroup3 Count: OU:OU=MyGroups,DC=corp,DC=bb,DC=lab
GROUP:TGroup4 Count:1 OU:OU=MyGroups,DC=corp,DC=bb,DC=lab
GROUP:TGroup5 Count:2 OU:OU=MyGroups,DC=corp,DC=bb,DC=lab
….

The Beginning and the End (the process to)

In my powershell journeys I have found a huge quantity of glorious abilities wrapped up in this truly POWER shell. One of these superpowers is the concept of filter/function processing. While I do not consider myself a guru in any stretch I have done a good bit of work with functions and think I have a sound grasp of this ability.

I haven’t used filters that much so I will stick with what I know… functions. Oh… glorious functions! These have been the life blood of my powershell experience. I came from a VBScript back ground and have always been super anal (or lazy) about code reuse. I would always try to black box my code to be able to reuse later. While this is a good practice IMHO… it does tend to get lost sometimes… This is where I believe Powershell functions come in.

There a ton of things you can do with functions and I don’t have time to discuss them all, so I am going to focus on my favorite…. Begin, Process, and End oh my!

Lets start with the basic layout of a function:

  1. function foo{
  2.    write-host "Hello World"
  3. }

Ok… nothing spectacular there, but what if I want to be more specific to whom I say hello

  1. function foo{
  2.    param([string]$name)
  3.    Write-Host "Hello $name"
  4. }

This is nice… but still… nothing big going on. I mean seriously… what kinda scripting language can’t a take parameters.

  1. function foo{
  2.    Param([string]$name)
  3.    Begin{
  4.        # Only gets process at the Beginning
  5.        # Normally include Variable creation and functions
  6.        Write-Host "Starting"
  7.    }
  8.    Process{
  9.       # Gets process for each object in the pipe (if ones exist)
  10.       if($_){Write-Host "Hello $_"}
  11.    }
  12.    End{
  13.       # Always get processed once at the end
  14.       if($name){Write-Host "Hello $name"}
  15.    }
  16. }

Now… as trivial as this looks this function is truly amazing. It not only has the ability to take a parameter, but it can also take a pipe (pipe is explained below.)

Like I said, functions of lots of abilities but this is my favorite. Thanks to Jeffrey and the Team…. GREAT IDEA!!!

===============================================
pipe: A pipe is when you get the results of one command and pipe them to another… Kinda like you did in DOS or BASH, but instead of pass text… in powershell you pass objects.