-
Notifications
You must be signed in to change notification settings - Fork 35
/
GetSchema.ps1
79 lines (66 loc) · 2.92 KB
/
GetSchema.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
param(
# Table of all configuration parameters set at instance of connector
[System.Collections.ObjectModel.KeyedCollection[[string], [Microsoft.MetadirectoryServices.ConfigParameter]]]
$ConfigParameters,
# Contains any credentials entered by the administrator on the Connectivity tab
[parameter(Mandatory = $true)]
[Alias('PSCredential')]
[System.Management.Automation.PSCredential]
$Credential,
# Path to debug log
[String]
$LogFilePath = "$([System.Environment]::GetEnvironmentVariable('Temp', 'Machine'))\MIMPS_SchemaScript.log",
# Optional parameter for manipulation by the TestHarness script.
[parameter(Mandatory = $false)]
[ValidateScript({ Test-Path $_ -PathType "Container" })]
[string]
$ScriptDir = [System.Environment]::GetEnvironmentVariable('Temp','Machine')
)
function Write-Log {
<#
.SYNOPSIS
Function for logging, modify to suit your needs.
#>
[CmdletBinding()]
param([string]$Message, [String]$Path)
# Uncomment this line to enable debug logging
# Out-File -InputObject $Message -FilePath $Path -Append
}
$PSDefaultParameterValues['Write-Log:Path'] = $LogFilePath
#region Import modules
try {
$commonModule = Join-Path -Path ([System.Environment]::GetEnvironmentVariable('Temp', 'Machine')) -ChildPath $ConfigParameters['Common Module Script Name (with extension)'].Value
Import-Module -Name $commonModule -Verbose:$false -ErrorAction Stop
Write-Log -Message "CommonModule imported"
} catch {
throw "Failed to import modules"
}
Write-Log -Message "Modules imported OK"
#endregion
#region Initiate Script
Write-Log -Message "Creating new schema object"
$Schema = New-xADSyncPSConnectorSchema
#endregion
#region Building Schema
$UserBaseAttributes = @{
'dn' = @{Multivalued=$False;DataType='String';SupportedOperation='ImportExport'}
'mailNickname' = @{Multivalued=$False;DataType='String';SupportedOperation='ImportExport'}
'sAMAccountName' = @{Multivalued=$False;DataType='String';SupportedOperation='ImportExport'}
'_MailboxType' = @{Multivalued=$False;DataType='String';SupportedOperation='ImportExport'}
'_isMailboxEnabled' = @{Multivalued=$False;DataType='Boolean';SupportedOperation='ImportExport'}
}
foreach($TypeName in 'User') {
Write-Log -Message "Processing $Type Schema"
$TypeObject = New-xADSyncPSConnectorSchemaType -Name $TypeName
Write-Log -Message "Adding Anchor attribute"
Add-xADSyncPSConnectorSchemaAttribute -Name 'objectGuid' -DataType 'Binary' -SupportedOperation 'ImportExport' -InputObject $TypeObject -Anchor
Write-Log -Message 'Adding Base attributes'
foreach($Attribute in $UserBaseAttributes.GetEnumerator()) {
$Param = $Attribute.Value.Clone()
if(-Not$Param.Multivalued){$Param.Remove('MultiValued')}
Add-xADSyncPSConnectorSchemaAttribute -Name $Attribute.Name @Param -InputObject $TypeObject
}
$Schema.Types.Add($TypeObject)
}
#endregion
Write-Output $Schema