Quantcast
Channel: VMware Communities : Unanswered Discussions - vRealize Automation Tools
Viewing all articles
Browse latest Browse all 6792

vRA 7.6 software component powershell create OU and join VM fails with exit value 1

$
0
0

Hi together,

 

hopefully someone could help because I'm getting crazy with this problem.

My plan is to deploy a VM with vRA 7.6 and everything works exept the powershell software component.

 

This powershell script should only get the variable from custom form and check the AD if OU exists or not, create if not exist and join the VM to domain.

 

# username password for AD join

$password = "xxx" | ConvertTo-SecureString -asPlainText -Force

$username = "xxx"

 

 

$ADcredential = New-Object System.Management.Automation.PSCredential($username,$password)

 

# Set DomainController for specific Domain

$domainController = (Get-ADDomainController -Domain $Domain -Discover -Writable -SiteName "Backbone").HostName[0].ToString()

 

 

 

 

 

 

 

 

 

try{

Get-ADOrganizationalUnit -Identity $TargetOU -Credential $ADcredential -Server $domainController

}

catch{

New-ADOrganizationalUnit -Name $createOUName -Path "$CreateOUPath" -ProtectedFromAccidentalDeletion $false -Credential $ADcredential -Server $domainController -ErrorAction Ignore

}

#AD join

Add-Computer -DomainName $Domain -OUPath $TargetOU -Credential $ADcredential -Server $domainController -PassThru -Verbose #-Restart

$LASTEXITCODE = 0

$LASTEXITCODE

exit

( code insertion doesn't work as expected :-( )

 

What I've checked:

- if the OU exist the PS script is working and join the new VM to the given OU

- when I've changed $createOUPath variable to a static entry the PS script is working and a new OU is created and VM joined to this OU

- when I execute the script locally on a VM template it is working without any error

- I've added $LASTEXITCODE and -ErrorAction Ignore and still getting: "ABORT. Encountered error in Powershell. Error while executing script: Process exited with an error: 1 (Exit value: 1)" but $LASTEXITCODE is shown with value 0?!

 

So I know that the problem is the $CreateOUPath variable because (as mentioned above) when I'll enter there static entry it works.

Did someone know what I'm doing wrong?

 

Thank you guys.

 

 


Viewing all articles
Browse latest Browse all 6792

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>