簡體   English   中英

PowerShell中函數調用函數的問題

[英]Problem with function calling function in 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命令在服務器上顯示沒有這樣的對象。

這是輸出:

********** Get Command Outout *********
CN=123413-NPARC,OU=Role Groups-Computer,OU=Centrify,OU=Operations,DC=qateradatacloud,DC=com
CN=AWS,CN=qateradatacloud,CN=Zones,OU=Centrify,OU=Operations,DC=qateradatacloud,DC=com
123413-NPARC

System.DirectoryServices.DirectoryServicesCOMException (0x80072030): There is no such object on the server.

at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.RefreshCache(String[] propertyNames)
at 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(Session session)
at Centrify.DirectControl.PowerShell.Types.CdmAdObject.Bind(Session session)
at Centrify.DirectControl.PowerShell.Commands.NewCdmComputerRole.InnerBeginProcessing()
at Centrify.DirectControl.PowerShell.CmdletBase.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()

最后,我將整個腳本分成兩個腳本。 一個用於Create AG-Group,另一個用於所有Centrify命令

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM