WMI Script to remote access a virtual machine on Hyper-V
-
03 Mei 2012 7:02
Dear All:
First, thank you for your help. This forum is really helpful.
This is a duplicate post as I post in Here. I am sorry for this. Just want this post could be viewd by many people. If it is not appropriate, I will remove the post. Thanks
I set up a Hyper-V on Windows Server 2008 R2 for hosting virtual machines. Now, in WS2008, I want to have a script (on WS2008 )which can execute a program in the virtual machine (remote site). So, I want to use the WMI to do the job.
I find the examples code on the web. One possible example is as following (from Here).
Function New-RemoteProcess { Param([string]$computername=$env:computername, [string]$cmd=$(Throw "You must enter the full path to the command which will create the process.") ) $ErrorActionPreference="SilentlyContinue" Trap { Write-Warning "There was an error connecting to the remote computer or creating the process" Continue } Write-Host "Connecting to $computername" -ForegroundColor CYAN Write-Host "Process to create is $cmd" -ForegroundColor CYAN [wmiclass]$wmi="\\$computername\root\cimv2:win32_process" #bail out if the object didn't get created if (!$wmi) {return} $remote=$wmi.Create($cmd) if ($remote.returnvalue -eq 0) { Write-Host "Successfully launched $cmd on $computername with a process id of" $remote.processid -ForegroundColor GREEN } else { Write-Host "Failed to launch $cmd on $computername. ReturnValue is" $remote.ReturnValue -ForegroundColor RED } }In PowerShell, type: <filename>.ps1 -comp "VM_NAME" -cmd "THE_PATH_OF_PROGRAM"
I did configure my WS2008 and VM as following many article on MSDN:
1. Open the port on firewall or just disable the both firewall (see Here)
2. Add administrators account in DCOM (dcomcnfg) or just open rights for everyone
3. The log in account name and password are the same in WS2008 and Win7 VM. And also in the same workgroup.
4. Run PowerShell as administrator
5. WMI service is running on both virtual machine
However, the connection to VM is still not built. Is there anyone can give some suggestion?
Thank you very much!!!
Semua Balasan
-
04 Mei 2012 7:04Moderator
Hi,
It is recommended that you to get further support in the corresponding community so that you can get the most qualified pool of respondents. Thanks for your understanding.
For your convenience, I have list the related link as followed.
The Official Scripting Guys Forum
http://social.technet.microsoft.com/Forums/en-US/ITCG/threads
- Ditandai sebagai Jawaban oleh Vincent HuModerator 07 Mei 2012 7:48
-
07 Mei 2012 11:26
Thank you very much for the reply!!