0

i am looking for a method to send a wmi command (to be specific "wmic process") to a virtual machine (hosted with Hyper-V 2016) and get its output. I am watching the windows deployment installation status of the virtual machine with powershell and need to wait for a process to start (in the vm).

The vm is in the windows Pre-Environment status at this moment, so i cannot enabled powershell remoting (because powershell is not enabled at this state)

neaerae
  • 11
  • 2
  • I'll make a note of caution: We've had a wide variety of issues having an external orchestrator attempt to reach into a freshly deploying machine. It's been far more reliable to have the deploying reach out and notify the orchestrator when it reaches a desired state. You can configure the PXE image with options shown here, for example: https://technet.microsoft.com/en-us/library/cc766521(v=ws.10).aspx – Matthew Wetmore Nov 04 '17 at 17:39

1 Answers1

0

This is a bit of a catch-22 situation. Powershell Remoting is really just a nice feature built on top of/around WinRM/WSMan/CIM, so to say that you cannot enable powershell remoting is the visible symptom of not being able to access WinRM/WSMan, which means you cannot use WMI/CIM.

If things were already in a desired state, you could just run Test-WSMan. Unfortunately, that doesn't seem to be your situation.

Assuming you are using no automation, such as SCCM or loading scripts into an image you're deploying, you're in a tough spot for these primary reasons:

  1. WinRM service does not have listeners configured by default
  2. Firewall is closed to WinRM ports
  3. Hyper-V does not provide access to this information by default
  4. ICMP is disabled by default

Your remedy depends a lot on your environment. In our environment we:

  1. Use DISM to load a powershell script into a stock image from Microsoft
  2. Configure WDS with the bare minimum to install the OS and start the script
  3. Join the computer to the domain through the script

Once joined to the domain, GPP allows us to ensure, among other things:

  1. WinRM listeners are configured
  2. Necessary firewall ports are opened
  3. ICMP is enabled

You could also:

  • Create a golden image
  • Manually join to the domain to get the GPP configurations
  • Use SCCM or some other desired state system
  • Create a golden VHD that you clone for other machines

You did not provide much more about the details of your environment, so this is just a 1,000 meter view.

Jonathon Anderson
  • 288
  • 1
  • 3
  • 10