Public/Export-ADUsersForBB.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Function Export-ADUsersForBB {
    <#
    .SYNOPSIS
        Get user information from ActiveDirectory with the information needed in GoBright BrightBooking and export it to a CSV file for import 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 ExportCsvPath
        Optional ActiveDirectory User Property which contains the pincode
    .EXAMPLE
        Export-ADUsersForBB -Filter * -ExportCsvPath "BrightBookingUsers.csv"
        # Get all users in the Active Directory and export to a GoBright BrightBooking users CSV file
    .EXAMPLE
        Export-ADUsersForBB -Filter * -SearchBase "OU=Office,DC=Company,DC=com" -ExportCsvPath "BrightBookingUsers.csv"
        # Get the users in the Active Directory, which are member of the given group and export to a GoBright BrightBooking users CSV file
    .EXAMPLE
        Export-ADUsersForBB -Filter { memberOf -RecursiveMatch "CN=Administrators,DC=Company,DC=com" } -SearchBase "OU=Office,DC=Company,DC=com" -ADUserPincodePropertyName PersonnelNumber -ADUserNamePropertyName FullUserName -ExportCsvPath "BrightBookingUsers.csv"
        # Get the users in the Active Directory, which in the specified SearchBase path, and use the custom property 'PersonnelNumber' as pincode, the custom property 'FullUserName' as username and export to a GoBright BrightBooking users CSV file
    .LINK
        https://support.gobright.com/
    .LINK
        https://technet.microsoft.com/library/hh852208.aspx
    .LINK
        Get-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=$True)]
       [string]$ExportCsvPath    
    )

    Process {
        $ConvertUsersParams = @{}
        
        $ADUsersParams = @{
            Filter = $Filter
        }
        If ($SearchBase) {
            $ADUsersParams.SearchBase = $SearchBase
        }
        If ($Server) {    
            $ADUsersParams.Server = $Server
        }
        If ($ADUserPincodePropertyName) {
            $ADUsersParams.ADUserPincodePropertyName = $ADUserPincodePropertyName
            $ConvertUsersParams.ADUserPincodePropertyName = $ADUserPincodePropertyName
        }
        If ($ADUserNamePropertyName) {
            $ADUsersParams.ADUserNamePropertyName = $ADUserNamePropertyName
            $ConvertUsersParams.ADUserNamePropertyName = $ADUserNamePropertyName
        }
        If ($ADUserMobilePropertyName) {
            $ADUsersParams.ADUserMobilePropertyName = $ADUserMobilePropertyName
            $ConvertUsersParams.ADUserMobilePropertyName = $ADUserMobilePropertyName
        }
        If ($ADUserNFCIdPropertyName) {
            $ADUsersParams.ADUserNFCIdPropertyName = $ADUserNFCIdPropertyName
            $ConvertUsersParams.ADUserNFCIdPropertyName = $ADUserNFCIdPropertyName
        }
        
        Get-ADUsersForBB @ADUsersParams | Convert-ADUsersToBBUserExport @ConvertUsersParams | Export-Csv -Path $ExportCsvPath -NoTypeInformation -Encoding UTF8
    }

}