VMware Cloud Community
IntegraRoger
Enthusiast
Enthusiast

Unique String in vRA 7.2

OK, this is starting to get me perturbed... I'm trying to use _resource~SystemIdentifier~MachineName of a system as a unique identifier so I can build a CSV file with which to configure a Sharepoint farm. Her is what I am getting as an error:

Checking if CSV exists...

Creating Temp Directory \\osfi-dml-01.devosfi.ca\Transient-Files\T2GrrTstDV0178

New-Item : The path is not of a legal form.

At C:\Users\darwin\AppData\Local\Temp\eca0aa7f-e761-4fc4-812c-029311dc8d04\task

.ps1:18 char:4

+    New-Item -ItemType Directory -Force -Path $TempPath -Name $RefDir

+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (\\osfi-dml-01.d...ransient-Files\:String) [New-Item], ArgumentException

    + FullyQualifiedErrorId : CreateDirectoryArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

---- SNIP ----

ABORT. Encountered error in Powershell.

Error while executing script: Process exited with an error: 1 (Exit value: 1)

I've tried using the variable directly ($ReferenceNost),

I've tried using the first item in the array (if it sees it): if ($ReferenceHost.count -gt 1) { $refHost = $ReferenceHost[0] } else { $refHost = $ReferenceHost }

I've tried taking the CR out of the string...

if I use Write-Output "--$ReferenceHost--" I get this:

--T2TstSQLBI0038

--

or sometimes this:

--T2TstSQLBI0038--

This is starting to drive me CRAZY... All I want to do is have a unique identifier with which to create a folder to house a god damn CSV file...

Suggestions??

Reply
0 Kudos
5 Replies
jasnyder
Hot Shot
Hot Shot

I am able to replicate this problem if I try to create a directory on a UNC path to which I haven't authenticated (and to which my current account does not have access).

So my guess is that either your path is wrong or more probably that the account executing the powershell script doesn't have permissions to the share specified in the UNC path you provided.

Take a look here for an idea on possible resolving this; however, it would require putting the credentials in the script which you probably don't want to do.

http://antonkallenberg.com/2013/04/20/powershell-unc-path-credentials/

It looks like you're using the Darwin bootstrap agent to do this (i.e. software components).  You should look at which user the darwin agent is running as and make sure it has network permissions to the share you're trying to access.

To test the theory, log in to a built server as the user that runs the darwin/bootstrap agent, and test the powershell new-item command as written to see if you can replicate the problem.  Then try as a different user which has access to the share and see if you get a different result.

Reply
0 Kudos
IntegraRoger
Enthusiast
Enthusiast

I'm using the local darwin account which is set as a local administrator. the UNC path is also owned by the local darwin account on the target system (different VM). It has everyone as read/write and the share is the same permissions (its swing space, so permissions are wide open by design).

Will test it and report back.

Reply
0 Kudos
IntegraRoger
Enthusiast
Enthusiast

Interactively, it works fine... ergo, the hair loss... Also, if I run the EXACT same script interactively it works fine. Here is the code I'm attempting to use...

Write-Output "Checking if CSV exists..."

$TempPath = "\\dml-01.local.org\Transient-Files\"

# Change potential Array variables to string variables

# if ($ReferenceHost.count -gt 1) { $refHost = $ReferenceHost[0] } else { $refHost = $ReferenceHost }

# if ($HostName.count -gt 1) { $ThisHost = $HostName[0] } else { $ThisHost = $HostName }

$refHost = $ReferenceHost

$ThisHost = $HostName

#set unique directory path to the configured ServerRoles.csv on \\dml\Transient-Files

$UniquePath=$TempPath+$refHost

if ( !(Test-Path -Path $UniquePath) ) {

   Write-Output "Creating Temp Directory $UniquePath"

   New-Item -ItemType Directory -Force -Path $TempPath -Name $RefDir

}

The New-Item line above is where I get the error...

Reply
0 Kudos
IntegraRoger
Enthusiast
Enthusiast

and, just to add insult to injury...

OK I’m going crazy…

These are defined as such:

ReferenceHost

The hostname that serves as the Unique Identifier: MUST RUN FIRST

String

Yes

_resource~CSV-Test~MachineName

No

Yes

Yes

No

No

HostName

use _resource~ThisHostName~MachineName

String

Yes

_resource~CSV-Test~MachineName

No

Yes

Yes

No

No

Code to test these…

Write-Output "Test for string --$HostName-- and --$ReferenceHost--"

$HostName -is [String]

$ReferenceHost-is [String]

Write-Output "Test for Array --$HostName-- and --$ReferenceHost--"

$HostName -is [Array]

$ReferenceHost-is [Array]

And, Results….

Test for string --T2csvtestDV0180-- and --T2csvtestDV0180--

False

False

Test for Array --T2csvtestDV0180-- and --T2csvtestDV0180--

True

True

Reply
0 Kudos
jasnyder
Hot Shot
Hot Shot

Well one thing to test is to have it create the directory in the local file system.  So instead of

$TempPath = "\\dml-01.local.org\Transient-Files\"

Try

$TempPath = "C:\temp\"

Or something similar, just to see if the problem is with the name of the directory (i.e. the property you receive from the software component) or with the location you're attempting to create the directory in.

While you're at it, you could log the current username just to make sure the script is executing as the user you think it is:

Write-Output ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)

If writing to the local file system works, then I would go back to it being a UNC problem.  At that point, try hardcoding the username and password using the net use trick from that blog post I linked to before scoping the username as "MACHINENAME\darwin" where machine is the server hosting the file share and see if that gets you anywhere.

As for why you're getting an array instead of a string... doesn't make much sense, but since you're dealing with that scenario, it doesn't seem like it's causing the error, especially since the error you're getting is indicating that it received a string as input.

Reply
0 Kudos