First of all we say the need: a user created some virtual machines, we can get a specific name of the virtual machine through get-scipaddress, but if we want to get the IP of the virtual machine in bulk from a description, this time through "pipeline" and "direct command" is not available.
This time, you need to use the loop.
For example, the following example, the virtual machine GET-VM obtained by the description section, the bottom of these "xxxx new machine in place to require 16G these characters", and the description of the use of get-scipaddress part of the GET-VM name. So we need to use the same attribute here, that is the name part of the GET-VM, and the description part of Get-scipaddress. The results are obtained through two commands.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/7D/wKioL1V-eMSx95GjAAM5RkfMuEQ532.jpg "title=" 2015-6-15 14-54-28.jpg "alt=" Wkiol1v-emsx95gjaam5rkfmueq532.jpg "/>
Nonsense not much to say directly on the script
Import-module VIRTUALMACHINEMANAGER$VVM =get-scipaddress |where {$_. Description-like "Fortress of Frontier City *"}|select NAME,DESCRIPTION$VCB = get-vm|where {$_. Description-like "* Li Huan *"}|select Nameforeach ($CB in $VVM) {foreach ($CCB in $VCB) {if ($CB. Description-eq $CCB. Name) {echo $CB}}}
In fact, the work of the script is slightly more complicated, it first uses get-scipaddress where to select a bit, the Description section has a similar fortress city properties, next in the description section of GET-VM, search for the name of the part of Li Huan
Next, go to a loop, look for the same description and name of the two commands, and print it out. Implemented through two nested loops.
In fact, the above foreach statements can be implemented with simpler statements.
foreach ($CB in $VVM) {if ($_.cb.description-eq $_.ccb.name) {echo $CB}}
This is actually through the $_. The method of the function reduces the input characters, the two methods are easier to read, the second is more concise under the premise of proficiency.
This article is from the "Nine uncle-Microsoft Private Cloud" blog, please make sure to keep this source http://jiushu.blog.51cto.com/972756/1662030
PowerShell Gets the virtual machine IP address for a specific "description"