Проблема с функцией вызова функции в PowerShell

У меня есть две функции:

  1. CreateComputer-Group
  2. CreateCoomputer-Role

После выполнения первой функции GroupCreated в первой функции используется во второй функции для создания роли компьютера. Как я могу убедиться, что выполнение первой функции завершено, а затем только вторая функция для выполнения.

Вот код:

$global:usergroup = "TACACS Admins"
$global:computerrole = "123413-NPARC"
$global:zone = "AWS"
$username = "<>"
$password = "<>"
[String[]] $global:HostServers = 'smp001-01','sl1ps01-13-8'
#[String[]] $global:HostServers = $hostServer.Replace("'","").Split(",")

Import-Module ActiveDirectory
Import-Module Centrify.DirectControl.PowerShell

$Password = ConvertTo-SecureString $password -AsPlainText -Force
$global:Cred = New-Object System.Management.Automation.PSCredential($username, $Password)
Set-CdmCredential -Domain test.com -Credential $Cred

function CreateComputer-Group {
    Param($Cred,$zone,$computerrole)
    try {
        New-ADGroup -Path "ou=Role Groups-Computer,ou=Centrify,ou=Operations,dc=qateradatacloud,dc=com" -Name $computerrole -GroupScope Global -GroupCategory Security -Credential $Cred -ErrorAction Stop
    } catch {
        $ErrorMessage = $_.Exception
        return $ErrorMessage
        break
    }
}

function create-computerRole {
    try {
    $ADGroupName = Get-ADGroup -Identity $computerrole
        Write-Host "********** Get Command Outout *********"
        Write-Host $ADGroupName
        Write-Host $CustomerZone
        Write-Host $computerrole

        $global:Hellow = New-CdmComputerRole -Zone $CustomerZone -Name $computerrole -Group $ADGroupName
        Write-Host $Hellow
    } catch {
        $ErrorMessage = $_.Exception
        return $ErrorMessage
    }
}

Не уверен почему New-CdmComputerRole команда, показывающая отсутствие такого объекта на сервере.

Вот вывод:

   ********** Получить команду Outout *********
CN=123413-NPARC,OU= Ролевые группы-Компьютер, OU = Центрифуга, OU = Операции,DC=qateradatacloud,DC=com
CN=AWS,CN=qateradatacloud,CN=Zones,OU=Centrify,OU= Операции, DC = qateradatacloud, DC = ком
123413-NPARC

System.DirectoryServices.DirectoryServicesCOMException (0x80072030): такого объекта на сервере нет.

в System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
в System.DirectoryServices.DirectoryEntry.Bind()
в System.DirectoryServices.DirectoryEntry.RefreshCache(String[] propertyNames)
в Centrify.DirectControl.Util.AD.DirectoryEntryEx.RefreshCache(DirectoryEntry de, String[] propertyNames)
at Centrify.DirectControl.Util.ActiveDirectory.Session.GetDirectoryEntryCheckOffline(String domainDcIpNetbios, String dn, String[] propertiesToLoad)
at Centrify.DirectControl.Util.ActiveDirectory.Session.GetDirectoryEntry(String domainDcIpNetbios, String dn, String[] propertiesToLoad)
at Centrify.DirectControl.Util.ActiveDirectory.Session.GetDirectoryEntry(String dn, String[] propertiesToLoad)
at Centrify.DirectControl.PowerShell.Types.CdmAdPrincipal.BindDirectoryEntry(сеанс сеанса)
at Centrify.DirectControl.PowerShell.Types.CdmAdObject.Bind(сеанс сеанса)
at Centrify.DirectControl.PowerShell.Commands.NewCdmComputerRole.InnerBeginProcessing()
at Centrify.DirectControl.PowerShell.CmdletBase.BeginProcessing()
в System.Management.Automation.Cmdlet.DoBeginProcessing()
в System.Management.Automation.CommandProcessorBase.DoBegin()

1 ответ

Наконец, я разделил весь сценарий на два сценария. Один для создания группы AG и другой для всех команд Centrify

Другие вопросы по тегам