Public/Get-ADUsersForBB.ps1
Function Get-ADUsersForBB { <# .SYNOPSIS Get user information from ActiveDirectory with the information needed in GoBright BrightBooking .DESCRIPTION Get user information via the Get-ADUser command, retreiving the information needed for GoBright BrightBooking. (Requiring RSAT tools: Remote Server Administration Tools) .PARAMETER Filter A filter used to pass to Get-ADUser, if you don't need a filter, then use: '*' Example: 'samAccountName -like "admin*"' More information: https://technet.microsoft.com/en-us/library/hh531527(v=ws.10).aspx .PARAMETER SearchBase A SearchBase used to pass to Get-ADUser, specifies an Active Directory path to search under. Example: "OU=Office,DC=Company,DC=com" More information: https://technet.microsoft.com/library/hh852208.aspx .PARAMETER Server Specifies the AD DS instance to connect to, by providing one of the following values for a corresponding domain name or directory server. More information: https://technet.microsoft.com/library/hh852208.aspx .PARAMETER ADUserPincodePropertyName Optional ActiveDirectory User Property which contains the pincode .PARAMETER ADUserNamePropertyName Optional ActiveDirectory User Property which contains the name of the user, in case you do not want to use the default property .PARAMETER ADUserMobilePropertyName Optional User Property which contains the mobile phone number .PARAMETER ADUserNFCIdPropertyName Optional User Property which contains the NFC Identifier, note that this must be in hex format, example: XX:XX:XX .PARAMETER ADUserDefaultCostCenterIdOrNamePropertyName Optional User Property which contains the Default Cost Center for the user, which can be the Name or the Id, both the name or id can be found in the GoBright portal .EXAMPLE Get-ADUsersForBB -Filter * # Get all users in the Active Directory .EXAMPLE Get-ADUsersForBB -Filter { memberOf -RecursiveMatch "CN=Administrators,DC=Company,DC=com" } -SearchBase "OU=Office,DC=Company,DC=com" # Get the users in the Active Directory, which are member of the given group .EXAMPLE Get-ADUsersForBB -Filter * -SearchBase "OU=Office,DC=Company,DC=com" -ADUserPincodePropertyName PersonnelNumber -ADUserNamePropertyName FullUserName # Get the users in the Active Directory, which in the specified SearchBase path, and use the custom property 'PersonnelNumber' as pincode, and the custom property 'FullUserName' as username .LINK https://support.gobright.com/ .LINK https://technet.microsoft.com/library/hh852208.aspx .LINK Export-ADUsersForBB .LINK Convert-ADUsersToBBUserExport #> [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string]$Filter, [Parameter(Mandatory=$False)] [string]$SearchBase, [Parameter(Mandatory=$False)] [string]$Server, [Parameter(Mandatory=$False)] [string]$ADUserPincodePropertyName, [Parameter(Mandatory=$False)] [string]$ADUserNamePropertyName, [Parameter(Mandatory=$False)] [string]$ADUserMobilePropertyName = "Mobile", [Parameter(Mandatory=$False)] [string]$ADUserNFCIdPropertyName, [Parameter(Mandatory=$False)] [string]$ADUserDefaultCostCenterIdOrNamePropertyName ) Process { $ADUsersParams = @{ Filter = $Filter } If ($SearchBase) { $ADUsersParams.SearchBase = $SearchBase } If ($Server) { $ADUsersParams.Server = $Server } $ADUsersProperties = @("SamAccountName","DistinguishedName","DisplayName","ProxyAddresses","Mail","MemberOf") If ($ADUserPincodePropertyName) { $ADUsersProperties += $ADUserPincodePropertyName } If ($ADUserNamePropertyName) { $ADUsersProperties += $ADUserNamePropertyName } If ($ADUserMobilePropertyName) { $ADUsersProperties += $ADUserMobilePropertyName } If ($ADUserNFCIdPropertyName) { $ADUsersProperties += $ADUserNFCIdPropertyName } If ($ADUserDefaultCostCenterIdOrNamePropertyName) { $ADUsersProperties += $ADUserDefaultCostCenterIdOrNamePropertyName } # Fetch the users from AD $ADUsers = Get-ADUser @ADUsersParams -Properties $ADUsersProperties | Select-Object * # Filter so we only get user objects $ADUsers = $ADUsers | Where-Object {$_.ObjectClass -eq "user"} # Return the found users Return $ADUsers } } |