dimitrios_thes
Contributor
Contributor

Software component with Powershell script fails because the software components properties values are not visible

Jump to solution

Dear all,

I am trying to execute the following Powershell script in the Configure action of a software component.

This script executes a PS script against a Domain Controller to Remove and Add a DNS record.

$user = "adminuser@ourdomain"

$pass = ConvertTo-SecureString "userpassword" -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential($user,$pass)

Invoke-Command -ComputerName "$domain_DC.$domain_fqdn" -Credential $cred -ScriptBlock { Remove-DnsServerResourceRecord -Name "$app_binding" -ZoneName "$domain_fqdn" -RRType "A" -Force }

Invoke-Command -ComputerName "$domain_DC.$domain_fqdn" -Credential $cred -ScriptBlock { Add-DnsServerResourceRecordA -Name "$app_binding" -ZoneName "$domain_fqdn" -IPv4Address "$app_web_node_ip" }

The following are properties defined in the software component, and they are assigned values in the blueprint.

$domain_DC

$domain_fqdn

$app_binding

$app_web_node_ip

I am using the same software component properties in the Install action of the software component which is a cmd. In the Install action no problem.

The error that I am getting is:

Cannot validate argument on parameter 'Name'. The argument is null or empty.

Supply an argument that is not null or empty and then try the command again.

    + CategoryInfo          : InvalidData: (:) [Remove-DnsServerResourceRecord

   ], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Remove-DnsServe

   rResourceRecord

    + PSComputerName        : dc1.ourdomain

Cannot validate argument on parameter 'Name'. The argument is null or empty.

Supply an argument that is not null or empty and then try the command again.

    + CategoryInfo          : InvalidData: (:) [Add-DnsServerResourceRecordA],

    ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DnsServerRe

   sourceRecordA

    + PSComputerName        : dc1.ourdomain

My feeling is that any software component properties that are inside the {  } curly braces script block they do not receive their values. It seams that the curly braces are causing some issue in the parsing of the code.

Does anybody has any idea how to fix this?

0 Kudos
1 Solution

Accepted Solutions
daphnissov
Immortal
Immortal

I see. It's assuming that variable exists remotely and it doesn't. In looking up the help for that cmdlet, you'll need to use the $Using option before your variable. See Invoke-Command​ and about_Remote_Variables | Microsoft Docs.

View solution in original post

5 Replies
daphnissov
Immortal
Immortal

Did you try specifying the PS variable without double quotes? This shouldn't be necessary since the replacement language will handle string quotation. I can't confirm if the braces are causing an issue, but I can test. Otherwise, if they are, something you can do I've done before as a workaround is to map the software component's properties as in-script variables. So at the top of your PS script you could do something like:

$myLocalVar1 = $domain_DC

$myLocalVar2 = $domain_fqdn

Then in your PS code, call $myLocalVar1 etc and any native formatting should then work.

0 Kudos
dimitrios_thes
Contributor
Contributor

I tried both tricks that you advised but unfortunately none of them worked.

I was pretty sure that the trick with the local variables would work, but it did not.

I would like to add here that the two variables $domain_DC and $domain_FQDN are receiving their values correctly, that is why I am suspecting that the curly braces are causing the issue, since the first variable inside the curly braces which is $app_binding is failing to receive a value, and then the execution of the script fails.

Needless to say that the script has been tested outside vRA and it works seamlessly.

Any other ideas please? I am really stack with this one.

0 Kudos
daphnissov
Immortal
Immortal

I see. It's assuming that variable exists remotely and it doesn't. In looking up the help for that cmdlet, you'll need to use the $Using option before your variable. See Invoke-Command​ and about_Remote_Variables | Microsoft Docs.

View solution in original post

dimitrios_thes
Contributor
Contributor

I had a look at the documentation you provided.

I think that this will work.

I will test it and let you know.

Thanks a lot

0 Kudos
dimitrios_thes
Contributor
Contributor

I have tested what daphnissov suggested and it worked like a charm Smiley Happy

Thank you very much for your support.

Thank you for spending your time investigating this.

0 Kudos