PowerShell examples

Door: Arnout van der Vorst
  • Move all mailboxes from Server1 to a target database on Server2.
    Get-Mailbox -Server Server1 | Move-Mailbox -TargetDatabase Server2Executives
  • Get all users from the OU “Gemigreerde Accounts” who don’t have UMRAMAILBOXMIGRATED in their Notes attribute and disconnect the mailbox from the user object.
    get-user -organizationalUnit “Gemigreerde Accounts” | where-object{$_.Notes -ne “UMRAMAILBOXMIGRATED”} | disable-Mailbox
  • Gets all processes which consume more than 400 handles and displayes them in a formatted list
    Get-Process | Where { $_.HandleCount -gt 400 } | Format-List
  • Get all users from the OU “Gemigreerde Accounts” and create a mailbox for these existing users in a database on EXC01, OWA is disabled. Perform the operation on dc01.tools4ever.local
    get-user -organizationalUnit “Gemigreerde Accounts” | where-object{$_.RecipientType -eq “User”} | Enable-Mailbox -Database “EXC01Mailbox Database” -DomainController “dc01.tools4ever.local”
  • Get all groups from the OU “Groepen” and set them as mail enabled with default settings.
    get-group -organizationalUnit “Groepen” | where-object{$_.RecipientType -eq “Group”} | Enable-DistributionGroup -DomainController “dc01.tools4ever.local”
  • Configures the mailbox to be hidden from the GAL and unable to receive any data.
    Set-Mailbox -Identity “CN=user,OU=Office,DC=tools4ever,DC=local” -HiddenFromAddressListsEnabled $true -MaxReceiveSize 0KB
  • Adds full access to janea to the mailbox specified by the identity parameter.
    Add-MailboxPermission -Identity “CN=user,OU=Office,DC=tools4ever,DC=local” -AccessRights FullAccess -user “janea”
  • Get mailbox permission from user account.
    get-Mailboxpermission -identity “CN=Arnout van der Vorst,OU=Gemigreerde Accounts,OU=DC=tools4ever,DC=local”
  • Get AD permissions (send-as/receive-as) from user account.
    get-ADpermission -identity “CN=Arnout van der Vorst,OU=Gemigreerde Accounts,DC=tools4ever,DC=local”
  • Get all users from the OU “Gemigreerde Accounts” and set the Notes attribute to an empty string
    get-user -organizationalUnit “Gemigreerde Accounts” | set-user -Notes “” Configures the mailbox with new proxyAddresses Set-Mailbox -Identity “CN=user,OU=Office,DC=tools4ever,DC=local” -ProxyAddresses “SMTP:[email protected],smtp:[email protected]
  • Adds the Full Access permission to a user’s mailbox object
    add-MailboxPermission -identity “CN=Arnout van der Vorst,OU=Gemigreerde Accounts,DC=tools4ever,DC=local” -user “CN=Ab Vos,OU=Gemigreerde Accounts,DC=tools4ever,DC=local” -AccessRights FullAccess
  • Removes the Full Access permission to a user’s mailbox object
    remove-MailboxPermission -identity “CN=Arnout van der Vorst,OU=Gemigreerde Accounts,DC=tools4ever,DC=local” -user “CN=Ab Vos,OU=Gemigreerde Accounts,DC=tools4ever,DC=local” -AccessRights FullAccess -Confirm:$false
  • Hides the mailbox from Address Book
    set-Mailbox -identity “CN=Arnout van der Vorst,OU=Gemigreerde Accounts,DC=tools4ever,DC=local” -HiddenFromAddressListsEnabled:$true
  • Multiple hide from Address Book
    get-user -organizationalUnit “Disabled Accounts” | set-Mailbox -HiddenFromAddressListsEnabled:$true
  • Get current domain, forest and PDC domain controller
    [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain() | Ft -property Name,Forest,PdcRoleOwner
  • Get PDC
    [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain().PdcRoleOwner.Name.ToString()
  • Get ACL on directory
    (get-acl c:data).access | ft
  • Get mailbox sizes (2007)
    Get-MailboxStatistics -Database exchangeDatabase | sort $_.TotalItemSize |FT DisplayName,ItemCount,TotalItemSize
  • Connect to Exchange 2003 WMI namespace for queries
    $MailboxInfo=get-wmiObject -class Exchange_Mailbox -namespace ROOTMicrosoftExchangeV2 -computername VM-WS03-AVO-001
  • Use ADSI to get AD objects
    $UserObject=[ADSI]”LDAP://CN=avdvorst2,OU=Baarn,OU=Offices,OU=Tools4ever,DC=t4evmdemo,DC=local”
  • Test if multi-value AD attribute (memberOf) contains a certain entry
    $UserObject.memberOf.contains(“CN=Lyon_Users,OU=Groups,OU=Tools4ever,DC=t4evmdemo,DC=local”)
  • Add/remove entry to user proxyAddresses
    $UserObject.proxyAddresses.remove(“”) or $UserObject.proxyAddresses.insert(“”)
  • Get the base OU path where an Active Directory object exists
    $UserObject.psbase.Parent.distinguishedName.ToString()
  • Get the number of values in a multi-value attribute (memberOf/proxyAddresses)
    $UserObject.proxyAddresses.psbase.Count

Geschreven door:
Arnout van der Vorst

Arnout van der Vorst is Identity Management Architect bij Tools4ever en al ruim 10 jaar in dienst. Arnout legt zich als Architect toe op het bedenken en ontwikkelen van nieuwe features, oplossingen en diensten van Tools4ever die aansluiten op de vraag uit de markt. Arnout studeerde Hogere Informatica aan de Hogeschool van Utrecht.

Anderen bekeken ook

De vooroordelen van Single Sign On

29 november 2011

RBAC: sleutelrol, beheer en evolutie

15 maart 2011

SAP koppeling met Active Directory

06 september 2012

Single Sign On met terminal emulatie (VAX64, AS/400, Linux, SSH)

14 oktober 2010

User- en toegangsbeheer in cloud applicaties: een uitdaging

04 september 2012