rjaudon
Contributor
Contributor

Powercli running Invoke-VMScript and Diskpart.exe against hangs

I am attempting to run a PowerCLI script to extend the Citrix D drive (WCDisk) 200+ VDI machines.  Running the script in PowerCLI on a test machine works fine up until it hits the Invoke-VMScript calling Diskpart.exe. It just hangs.  I think I've determined when attempting to call Invoke-VMScript to run diskpart to extend D drive (WCDisk) within the VDI OS UAC is blocking it from running because it just hangs…See screen shot below.

Also, from within the VDI that the script is running against, I can see the Diskpart.exe CMD process just sitting there in TaskMgr.

Here is the test script I am running..

$HostCredential = Get-Credential

$GuestCredential = Get-Credential

#This part hangs

Invoke-VMScript -HostCredential $HostCredential -vm Win10Test6 -GuestCredential $GuestCredential -ScriptText "C:\windows\system32\diskpart.exe /s c:\Windows\temp\diskpart.txt" -ScriptType BAT   *** This stalls out ***

If I substitute the Diskpart commands for a non-interactive command such as 'dir' the process runs without issue. This tells me the process and my userid is not the issue.

This one works just fine so I know my userid is correct..

#Invoke-VMScript -HostCredential $HostCredential -vm Win10Test6 -GuestCredential $GuestCredential -ScriptText "dir" *** Worked

NOTE:

•        I ‘think’ UAC might be causing an issue but that is a hunch. I’ve tried to disable UAC but that takes a reboot to set the value and truly be disabled.  This is a Citrix PVS env and UAC is on and the VDI machines reboot to a known state (UAC on).  I haven't gone as far as creating another image with UAC off to test.

Questions I need help with are:

  1. Is there a better or easier way to extend a drive via PS with UAC on?
  2. Is there a way to bypass UAC with use of Enter-PSSession running the same commands elevated?
0 Kudos
3 Replies
LucD
Leadership
Leadership

One way you could try:

  • copy psexec.exe (from the SysInternals Suite) to a location in the guest OS
  • with Invoke-VMscript
    • start psexec.exe with the -s option (system account) and/or the -h option (run with elevated token)
    • run diskpart as the <cmd> on the psexec


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

0 Kudos
rjaudon
Contributor
Contributor

Ah yes....I forgot about that.

Will try in the lab.

Thank you.

Rob

0 Kudos
rjaudon
Contributor
Contributor

LucD,

Thanks for the reminder...I think I have this going and with minimal testing it seems to work.

Import-Csv -Path 'C:\Temp\Test_VDI.csv' | %{

    $vmName = $_.Name

    $Dest = "\\" + $vmName + "\"+ "C$\temp"

    Copy-Item "C:\temp\Diskpart.txt" -Destination $Dest -Force

    c:\temp\psexec.exe -i -h \\win1002 diskpart.exe /s c:\temp\diskpart.txt

}

This copies the text file over then executes psexec which calls diskpart.exe.  Pretty cool. 

Thanks,

Rob

0 Kudos