VMware Cloud Community
erwabovm
Contributor
Contributor
Jump to solution

Powershell Script Results To Attribute

I am using the workflow "Run Script in VM" which is this powershell script:

$searcher = [ADSISearcher]'(&(objectCategory=computer)(name=DOMAINPC*))'

$searcher.PageSize = 1000

$last = $searcher.FindAll() | Foreach-Object { [int]($_.Properties.name -replace '\D').Trim() } | Sort-Object | Select-Object -Last 1

$digitLength = "$last".Length

$vmname= "{0}{1:D}" -f 'DOMAINPC',($last+1)

$vmname

[2017-11-01 12:11:21.515] [I] DOMAINPC205

IN VRO, it returns a name as expected DOMAINPC205. I'm outputting that text (at least I thought I was) to an attribute as a string as seen below

pastedImage_0.png

On my next workflow I'm using that output attribute as an input for creating a PC in an OU, but its always NULL., because the string value in the attribute is null. How can I get the results as a useable attribute?

pastedImage_1.png

I cannot seem to figure this out....any ideas?

Reply
0 Kudos
29 Replies
erwabovm
Contributor
Contributor
Jump to solution

Interesting further down in my log I see this

|  'attribute': name=scriptOutputTextOut type=string value=tr01VDSIIS223 

|  'attribute': name=computerName type=string value=__NULL__

So the OUTPUT to attribute works, but when i sue that as input, it shows as null....its not writing the value to the input attribute

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

The OUT bindings of the first scriptable task has some mapping from param to computerName out attribute. Where is this param coming from, and where is its value set? If not set, then it is normal for computerName attribute to be NULL.

Reply
0 Kudos
erwabovm
Contributor
Contributor
Jump to solution

I created that output parameter so I could have an output to the ComputerName attribute. I was assuming that that I needed an output to attribute to pass into the Create a Computer workflow.  The

That being said, even if I take that scriptable task out of the equation and just use the ScriptOutputTextOut attribute and an IN Attribute in Create a Computer I still get the issue. Like this

pastedImage_0.png

pastedImage_1.png

Reply
0 Kudos
erwabovm
Contributor
Contributor
Jump to solution

So after digging into this a little further, I added this in a Scriptable task:

scriptOutputTextOut = ComputerNameOut;

System.log("This is the computername output;" + ComputerNameOut);

The result was :

[2017-11-03 08:01:23.625] [I] This is the computername output;null

I also just did System.log(scriptOutputTextOut); 

So even thought it shows scriptOutputTextOut as a variable with the powershell results, the log still shows null. Makes no sense.

So Basically what is happening is its doing what its  being told to do, its running the powershell script, but there results of the script are not being output into the attribute string. Im not sure why, I dont know any other way to force that to happen.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

OK, I managed to reproduce the error in my lab.

The problem is that the name returned from PowerShell part, eg. DOMAINPC2, has an extra character(s) at the end (newline)

So you need to trim it before passing it as input to 'Create a computer ...' workflow.

Reply
0 Kudos
erwabovm
Contributor
Contributor
Jump to solution

Awesome! Thanks! That would be super if I knew how to do that.

Shouldn't this part of my script being doing that Foreach-Object { [int]($_.Properties.name -replace '\D').Trim() }

Reply
0 Kudos
erwabovm
Contributor
Contributor
Jump to solution

Okay i was able to get the variable to pass all the way through my keeping the name consistent as its tied to the workflow, but I still get the error which may be related to what you are saying...I jsut dont know how to trim it.

[2017-11-03 12:26:09.496] [I] TR01VDSIIS223

[2017-11-03 12:26:09.575] [I] TR01VDSIIS223

[2017-11-03 12:26:09.576] [I] This is the computername output;TR01VDSIIS223

[2017-11-03 12:26:09.661] [E] (com.vmware.library.microsoft.activeDirectory/createComputer) Error in (Dynamic Script Module name : createComputer#0) Failed to create computer... 00000523: SysErr: DSID-031A12C8, problem 22 (Invalid argument), data 0

[2017-11-03 12:26:09.676] [E] Workflow execution stack:

***

item: 'Create a computer in an organizational unit/item0', state: 'failed', business state: 'null', exception: 'Failed to create computer... 00000523: SysErr: DSID-031A12C8, problem 22 (Invalid argument), data 0

The error highlighted in red means there are extra characters as you said

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

One option would be to add a scriptable task between 'Run script in VM guest' and 'Create a computer ...' workflow elements, with the following content:

scriptOutputTextOut = scriptOutputTextOut.trim();

and add scriptOutputTextOut to both IN and OUT tabs of this task.

Need to check if and how this trimming can be done in the PowerShell script code.

Reply
0 Kudos
erwabovm
Contributor
Contributor
Jump to solution

YES!!! That worked OMG, i was so annoyed with this!  So  sbeaver had mentioned the .trim() but I had the IN/OUTs wrong since I used custom names which that workflow did not like!

ITs all working as expected.....Thanks a ton, spent a week on this!!

Reply
0 Kudos
erwabovm
Contributor
Contributor
Jump to solution

Sooooo.....I had to add another run PS in VM to get another variable...IP address. So I did the same steps. I got the script, then added a scriptable task to trim the results....however, I cant have the same OUTS or output attribute as my workflow for the server name itself. IT seems that unless I leave the OUT as its default of ScriptOutputTextOut, it will output nothing but null.

Doesnt make much sense, but I ran into that issue with my first one as seen its the previous posts here.  I added the 2 items circled below

pastedImage_0.png

pastedImage_1.png

Reply
0 Kudos