VMware Cloud Community
JLogan2016
Enthusiast
Enthusiast
Jump to solution

Trying to map drives in guest

I have been working on a script to deploy servers for a customer. The only piece that is left is mapping the additional vDisks to drive letters. I am 90% of the way there, but am stuck on assigning drive letters. If I run an Invoke-VMScript with this:

New-Partition -DiskNumber 4 -AssignDriveLetter -UseMaximumSize

it works just fine. However when I try to change the drive letter later on in the process:

Set-Partition -DriveLetter f -NewDriveLetter m

I get an error that the CIM session could not be created through Invoke-VMScript:

VM           : JLoTest01

ExitCode     : 0

ScriptOutput : New-Partition : Access to a CIM resource was not available to the client.

               At line:1 char:8

               + & {    New-Partition -DiskNumber 4 -AssignDriveLetter -DriveLetter M

               -UseMaximum ...

               +       

               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                   + CategoryInfo          : PermissionDenied: (MSFT_Disk:ROOT/Microsoft/Wind

                  ows/Storage/MSFT_Disk) [New-Partition], CimException

                   + FullyQualifiedErrorId : MI RESULT 2,New-Partition

I am guessing that piece requires it to be run with admin rights, as I get the same thing if I try to set it right off the bat:

New-Partition -DiskNumber 4 -AssignDriveLetter -DriveLetter M -UseMaximumSize

The customer I am working with disables use of WinRM, and have yet to be open to reasonable discussion on the topic, so this avenue is closed to me. I did try running this through an Invoke-WMIMethod call:

$mapDrive = @"

    New-Partition -DiskNumber 4 -AssignDriveLetter -DriveLetter M -UseMaximumSize

"@

   Invoke-wmiMethod -computername "JLoTest01" `

                    -class win32_process `

                    -name create `

                    -argumentlist “powershell.exe -command $($mapDrive)” `

                    -credential $creds `

                    -EnableAllPrivileges: $true

But I get a similar experience, if I do not specify the drive letter it works just fine. If I do, it simply returns immediately with no output.

So my question is whether there is some way around the launching as admin when going through Invoke-VMScript. I have done some Googling, but am coming up empty. I found a post that pointed to the function below, but haven't been able to get it to work through Invoke-VMScript.

Re-launch Powershell Script Elevated

Edit: I forgot to mention, the workflow is to clone from template, run customization, wait for customization to finish, then map the drives before first logon, pulling drive letter, label and size from a csv

0 Kudos
1 Solution

Accepted Solutions
JLogan2016
Enthusiast
Enthusiast
Jump to solution

Just as a way to wrap this up, I ended up resolving it by just looping through the block that assigns Drive Letters multiple times, to catch any that are missed on the first pass. All in all not an elegant solution, as the whole function of initializing, formatting and assigning letters to the drives adds up to 11 minutes to what was a sub-3 minute build script, but it works.

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect this might be a UAC issue.

You could eventually test that by disabling UAC on one target and running the Invoke-VMScript again against that target.

If UAC is indeed the issue, you could try the method I mentioned in Re: Re IP all windows VM in a VMware cluster, using vCenter login.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You might also want to have a look at this post Invoke-Command and Access to a CIM resource was not available


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
JLogan2016
Enthusiast
Enthusiast
Jump to solution

Thanks for the suggestions. I disabled UAC in both servers that I am testing on (2012 R2 and 2016) but still no joy. I will take a look at the article you mentioned; my main concern with that method is he is creating the Scheduled Task via a pssession; the inability to use this method is the root of my issue.

0 Kudos
JLogan2016
Enthusiast
Enthusiast
Jump to solution

Just as a way to wrap this up, I ended up resolving it by just looping through the block that assigns Drive Letters multiple times, to catch any that are missed on the first pass. All in all not an elegant solution, as the whole function of initializing, formatting and assigning letters to the drives adds up to 11 minutes to what was a sub-3 minute build script, but it works.

0 Kudos