4 Replies Latest reply on Oct 4, 2019 5:34 AM by JLogan2016

    Trying to map drives in guest

    JLogan2016 Enthusiast

      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