Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize minor fixes #1238

Open
wants to merge 9 commits into
base: modularize
Choose a base branch
from
8 changes: 4 additions & 4 deletions .openpublishing.build.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
param(
[string]$buildCorePowershellUrl = "https://opbuildstorageprod.blob.core.windows.net/opps1container/.openpublishing.buildcore.ps1",
[string]$buildCorePowershellUrl = 'https://opbuildstorageprod.blob.core.windows.net/opps1container/.openpublishing.buildcore.ps1',
[string]$parameters
)
# Main
$errorActionPreference = 'Stop'
$ErrorActionPreference = 'Stop'

# Step-1: Download buildcore script to local
echo "download build core script to local with source url: $buildCorePowershellUrl"
Write-Output "download build core script to local with source url: $buildCorePowershellUrl"
$repositoryRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
$buildCorePowershellDestination = "$repositoryRoot\.openpublishing.buildcore.ps1"
Invoke-WebRequest $buildCorePowershellUrl -OutFile "$buildCorePowershellDestination"

# Step-2: Run build core
echo "run build core script with parameters: $parameters"
Write-Output "run build core script with parameters: $parameters"
& "$buildCorePowershellDestination" "$parameters"
exit $LASTEXITCODE
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Get-EntraDirectoryObjectOnPremisesProvisioningError {
[CmdletBinding(DefaultParameterSetName = 'GetById')]
[OutputType([System.Object])]
param (
[Parameter(ParameterSetName = "GetById")][ValidateNotNullOrEmpty()][ValidateScript({if ($_ -is [System.Guid]) { $true } else {throw "TenantId must be of type [System.Guid]."}})][System.Guid] $TenantId
[Parameter(ParameterSetName = 'GetById')]
[ValidateNotNullOrEmpty()]
[ValidateScript({ if ($_ -is [System.Guid]) { $true } else { throw 'TenantId must be of type [System.Guid].' } })]
[System.Guid] $TenantId
)
PROCESS {
begin { }

process {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
if ($null -ne $PSBoundParameters["TenantId"]) {
$params["TenantId"] = $PSBoundParameters["TenantId"]
}
Write-Debug("============================ TRANSFORMATIONS ============================")
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
if ($null -ne $PSBoundParameters['TenantId']) {
$params['TenantId'] = $PSBoundParameters['TenantId']
}
Write-Debug('============================ TRANSFORMATIONS ============================')
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")
$Object = @("users", "groups", "contacts")
$Object = @('users', 'groups', 'contacts')
$response = @()

try {
foreach ($obj in $object) {
$obj = ($obj | Out-String).trimend()
$obj = ($obj | Out-String).TrimEnd()
$uri = 'https://graph.microsoft.com/v1.0/' + $obj + '?$select=onPremisesProvisioningErrors'
$response += ((Invoke-GraphRequest -Headers $customHeaders -Uri $uri -Method GET).value).onPremisesProvisioningErrors
}
} catch {
Write-Error $_.Exception.Message
}
catch {}
}

end {
if ([string]::IsNullOrWhiteSpace($response)) {
write-host "False"
}
else {
Write-Output 'False'
} else {
$response
}

}
}

Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Get-EntraBetaDirectoryObjectOnPremisesProvisioningError {
[CmdletBinding(DefaultParameterSetName = 'GetById')]
[OutputType([System.Object])]
param (
[Parameter(ParameterSetName = "GetById")][ValidateNotNullOrEmpty()][ValidateScript({if ($_ -is [System.Guid]) { $true } else {throw "TenantId must be of type [System.Guid]."}})][System.Guid] $TenantId
[Parameter(ParameterSetName = 'GetById')]
[ValidateNotNullOrEmpty()]
[ValidateScript({ if ($_ -is [System.Guid]) { $true } else { throw 'TenantId must be of type [System.Guid].' } })]
[System.Guid] $TenantId
)
PROCESS {

begin { }

process {
$params = @{}
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand
if ($null -ne $PSBoundParameters["TenantId"]) {
$params["TenantId"] = $PSBoundParameters["TenantId"]
if ($null -ne $PSBoundParameters['TenantId']) {
$params['TenantId'] = $PSBoundParameters['TenantId']
}
Write-Debug("============================ TRANSFORMATIONS ============================")
Write-Debug('============================ TRANSFORMATIONS ============================')
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")
$Object = @("users", "groups", "contacts")
$Object = @('users', 'groups', 'contacts')
$response = @()

try {
foreach ($obj in $object) {
$obj = ($obj | Out-String).trimend()
$obj = ($obj | Out-String).TrimEnd()
$uri = 'https://graph.microsoft.com/beta/' + $obj + '?$select=onPremisesProvisioningErrors'
$response += ((Invoke-GraphRequest -Headers $customHeaders -Uri $uri -Method GET).value).onPremisesProvisioningErrors
}
} catch {
Write-Error $_.Exception.Message
}
catch {}
}

end {
if ([string]::IsNullOrWhiteSpace($response)) {
write-host "False"
}
else {
Write-Host 'False'
} else {
$response
}
}
}

Original file line number Diff line number Diff line change
@@ -1,120 +1,118 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Set-EntraBetaDirSyncFeature {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(ParameterSetName = "GetQuery", Mandatory = $true, ValueFromPipelineByPropertyName = $true)][System.String] $Feature,
[Parameter(ParameterSetName = "GetQuery", Mandatory = $true, ValueFromPipelineByPropertyName = $true)][System.Boolean] $Enabled,
[Parameter(ParameterSetName = "GetQuery", ValueFromPipelineByPropertyName = $true)][System.Guid] $TenantId,
[switch] $Force
)
PROCESS {

$params = @{}
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand
if ($PSBoundParameters.ContainsKey("Verbose")) {
$params["Verbose"] = $Null
}
if ($null -ne $PSBoundParameters["Feature"]) {
$Feature = $PSBoundParameters["Feature"] + "Enabled"
}
if ($null -ne $PSBoundParameters["Enabled"]) {
$Enabled = $PSBoundParameters["Enabled"]
}
if ($PSBoundParameters.ContainsKey("Debug")) {
$params["Debug"] = $PSBoundParameters["Debug"]
}
if($null -ne $PSBoundParameters["WarningVariable"])
{
$params["WarningVariable"] = $PSBoundParameters["WarningVariable"]
}
if($null -ne $PSBoundParameters["InformationVariable"])
{
$params["InformationVariable"] = $PSBoundParameters["InformationVariable"]
}
if($null -ne $PSBoundParameters["InformationAction"])
{
$params["InformationAction"] = $PSBoundParameters["InformationAction"]
}
if($null -ne $PSBoundParameters["OutVariable"])
{
$params["OutVariable"] = $PSBoundParameters["OutVariable"]
}
if($null -ne $PSBoundParameters["OutBuffer"])
{
$params["OutBuffer"] = $PSBoundParameters["OutBuffer"]
}
if($null -ne $PSBoundParameters["ErrorVariable"])
{
$params["ErrorVariable"] = $PSBoundParameters["ErrorVariable"]
}
if($null -ne $PSBoundParameters["PipelineVariable"])
{
$params["PipelineVariable"] = $PSBoundParameters["PipelineVariable"]
}
if($null -ne $PSBoundParameters["ErrorAction"])
{
$params["ErrorAction"] = $PSBoundParameters["ErrorAction"]
}
if($null -ne $PSBoundParameters["WarningAction"])
{
$params["WarningAction"] = $PSBoundParameters["WarningAction"]
}

Write-Debug("============================ TRANSFORMATIONS ============================")
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
[OutputType([System.String])]
param (
[Parameter(ParameterSetName = 'GetQuery', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[System.String]
$Feature,

[Parameter(ParameterSetName = 'GetQuery', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[System.Boolean]
$Enabled,

[Parameter(ParameterSetName = 'GetQuery', ValueFromPipelineByPropertyName = $true)]
[System.Guid]
$TenantId,

[switch]
$Force
)

begin {
$params = @{}
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand
if ($PSBoundParameters.ContainsKey('Verbose')) {
$params['Verbose'] = $Null
}
if ($null -ne $PSBoundParameters['Feature']) {
$Feature = $PSBoundParameters['Feature'] + 'Enabled'
}
if ($null -ne $PSBoundParameters['Enabled']) {
$Enabled = $PSBoundParameters['Enabled']
}
if ($PSBoundParameters.ContainsKey('Debug')) {
$params['Debug'] = $PSBoundParameters['Debug']
}
if ($null -ne $PSBoundParameters['WarningVariable']) {
$params['WarningVariable'] = $PSBoundParameters['WarningVariable']
}
if ($null -ne $PSBoundParameters['InformationVariable']) {
$params['InformationVariable'] = $PSBoundParameters['InformationVariable']
}
if ($null -ne $PSBoundParameters['InformationAction']) {
$params['InformationAction'] = $PSBoundParameters['InformationAction']
}
if ($null -ne $PSBoundParameters['OutVariable']) {
$params['OutVariable'] = $PSBoundParameters['OutVariable']
}
if ($null -ne $PSBoundParameters['OutBuffer']) {
$params['OutBuffer'] = $PSBoundParameters['OutBuffer']
}
if ($null -ne $PSBoundParameters['ErrorVariable']) {
$params['ErrorVariable'] = $PSBoundParameters['ErrorVariable']
}
if ($null -ne $PSBoundParameters['PipelineVariable']) {
$params['PipelineVariable'] = $PSBoundParameters['PipelineVariable']
}
if ($null -ne $PSBoundParameters['ErrorAction']) {
$params['ErrorAction'] = $PSBoundParameters['ErrorAction']
}
if ($null -ne $PSBoundParameters['WarningAction']) {
$params['WarningAction'] = $PSBoundParameters['WarningAction']
}
Write-Debug('============================ TRANSFORMATIONS ============================')
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")
}

process {
if ([string]::IsNullOrWhiteSpace($TenantId)) {
$OnPremisesDirectorySynchronizationId = (Get-MgBetaDirectoryOnPremiseSynchronization).Id
}
else {
} else {
$OnPremisesDirectorySynchronizationId = Get-MgBetaDirectoryOnPremiseSynchronization -OnPremisesDirectorySynchronizationId $TenantId -ErrorAction SilentlyContinue -ErrorVariable er
if ([string]::IsNullOrWhiteSpace($er)) {
$OnPremisesDirectorySynchronizationId = $OnPremisesDirectorySynchronizationId.Id
}
else {
throw "Set-EntraBetaDirsyncFeature :$er"
} else {
throw "Set-EntraBetaDirSyncFeature :$er"
break
}
}

$body = @{
features = @{ $Feature = $Enabled }
}
$body = $body | ConvertTo-Json
if ($Force) {
# If -Force is used, skip confirmation and proceed with the action.
$decision = 0
}
else {
} else {
$title = 'Confirm'
$question = 'Do you want to continue?'
$Suspend = new-Object System.Management.Automation.Host.ChoiceDescription "&Suspend", "S"
$Yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Y"
$No = new-Object System.Management.Automation.Host.ChoiceDescription "&No", "N"
$Suspend = New-Object System.Management.Automation.Host.ChoiceDescription '&Suspend', 'S'
$Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Y'
$No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'N'
$choices = [System.Management.Automation.Host.ChoiceDescription[]]( $Yes, $No, $Suspend)
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
}
if ($decision -eq 0) {
$response = Update-MgBetaDirectoryOnPremiseSynchronization -Headers $customHeaders -OnPremisesDirectorySynchronizationId $OnPremisesDirectorySynchronizationId -BodyParameter $body -ErrorAction SilentlyContinue -ErrorVariable "er"
$response = Update-MgBetaDirectoryOnPremiseSynchronization -Headers $customHeaders -OnPremisesDirectorySynchronizationId $OnPremisesDirectorySynchronizationId -BodyParameter $body -ErrorAction SilentlyContinue -ErrorVariable 'er'
$er
break
if ([string]::IsNullOrWhiteSpace($er)) {
$response
} else {
Write-Error "Cannot bind parameter 'TenantId'. Cannot convert value `"$TenantId`" to type
`"System.Guid`". Error: `"Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).`""
}
else {
Write-Error "Cannot bind parameter 'TenantId'. Cannot convert value `"$TenantId`" to type
`"System.Guid`". Error: `"Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).`" "
}

}
else {

} else {
return
}


}
}

end { }
}
Loading