specify the name of the vm to get-view-filter of hash

According to me, Miss me some eccentric or a convention with Powershell variables in a hash filter.

My infrastructure includes these 3 VMs:
UTIL
otherUTIL
anotherUTILserver

I try to use something like the following to return only the virtual machine called UTIL. This returns all 3 VMs with UTIL in their name:

$vm = 'UTIL '.

Notice-EEG - ViewType VirtualMachine-filter @{"Name" = $vm} | Select - expand name

Get line - see below eliminates anotherUTILserver but always returns otherUTIL with UTIL:

Notice-EEG - ViewType VirtualMachine-filter @{'Name' = ' $$vm '} | Select - expand name

With ' $vm$ ' I'm following comment by LucD here: http://rvdnieuwendijk.com/2011/09/12/how-to-use-VMware-vSphere-PowerCli-to-find-the-MAC-addresses-of-a-virtual-machine/#comment-22

If necessary, I could use the GET more slow-but-more simple-vm, could add a foreach loop (my example is simplified), or might filter on an additional property in addition to the name. But I hope that there is a similar thing that will help you eliminate otherUTIL and filter return only UTIL, without adding complexity.

Regular expression to the rescue: http://msdn.microsoft.com/library/az24scfc.aspx

Notice-EEG - ViewType VirtualMachine-filter @{"Name" = "^ $vm$"} | Select - expand name

Or without regex:

$x = get-View - ViewType VirtualMachine-filter @{"Name" = $vm}

$x | where {$_.name - eq $vm} | Select - expand name

Tags: VMware

Similar Questions

  • The use of Get - view instead of Get - VM for the advanced settings of a virtual computer

    I have a question in relation to the advanced settings of a virtual machine and using Get - view instead of Get - VM for this particular case:

    Get - VM * | Get-AdvancedSetting - name "scsi * sharing | Select the entity, Name, Value

    My idea is to use:

    Notice-EEG - ViewType VirtualMachine. Where {-not $_.} Config.Template} | Where {$_.} {Advanced.Setting - eq ' scsi * sharing "} | Select the entity, Name, Value

    but as far as I can see there is nothing for the advanced configuration of 'VirtualMachine' here: https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FVirtualMachine.htm

    I also took a quick glance at https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.ConfigSpec.html , but I can't figure out how to use "extraConfig"in the script PowerCLI to extract this particular information for "Sharing of SCSI".»

    There is information how to use the API to add or change a computer virtual here .vmx file key advances: http://blogs.vmware.com/PowerCLI/2008/09/changing-vmx-fi.html but it is not clear to me how to use it just to extract information without changing what.

    Try like this

    foreach ($vm in (Get-View - ViewType VirtualMachine - property Name, Config.ExtraConfig - filter @{'Config.Template ' =' False'})) {}

    $vm. Config.ExtraConfig | where {$_.} Key - like "{scsi * sharing '} |"

    Select @{N = "VM"; E = {$vm. Name}},@{N='Template'; E = {$vm. Config.Template}}, Key, Value

    }

  • Folder is a virtual computer in the use of Get-View

    All, I run a script to collect information on the virtual machines in the environment, but have not been able to figure out how to get the file to in the virtual machine is.  I know I could use a get - vm | Select name, file etc. but at the time wherever I have add a get - vm statement, I'll add a TON of execution time of the script.

    I currently use it as my get-views command...

    Notice-EEG - ViewType VirtualMachine-Name property, Runtime.Host, Config.GuestFullName, Config.Annotation, Config.Hardware.NumCPU, Config.Hardware.MemoryMB, Guest.Disk, Config.Template, Guest.IpAddress | Sort-Object-property name. %{
    If ($_.) Config.Template - not $true) {}
    $row = "" | Select-Object Name, Notes, MemoryGB, host, CPU, OS, Cluster, IPAddress, DiskSpaceGB, UsedSpaceGB

    ....

    I know I'm just grabbing some properties, but I was not able to find the property that gives the name of the folder.

    To try to find the right one, I did

    $vm = get-View - ViewType VirtualMachine-filter @{"Name" ="VM_Name"}

    Then just walk through the $vm variable. (Property) etc.

    Anyone?

    In the VirtualMachine object, the Parent property contains the MoRef (pointer) to the object of the file.

    In order to

    Select Name,@{N="Folder; E = {Get-view $_.} Parent | Select name - ExpandProperty}}

  • Regular Get-view filter expressions

    I have the following code:

    $vms = get-VM-location 'test '.

    for ($i = 0; $i - lt $vms. County; $i++)

    {

    $vmOS = get-View - ViewType 'VirtualMachine' - filter @{"Name" = $vms [$i] .name} - property @("Nom", "Config.GuestFullName") | Select-Object - property name, @{N = "ConfiguredOS"; E={$_. Config.GuestFullName}}

    $vmOS

    }

    $vms contains some virtual machines to a folder called 'test '. I have 2 virtual machines in the folder - 'test' and 'test2 '. When I run the code above, when the 'test' VM is put in the loop, she returned twice. Time for 'test', and 'test2 '. I'm looking for a regular expression that I can use to get the exact name of each virtual computer so that only 1 value is returned by $vmOS in each loop.

    The filter is a regular expression, you can use the indicators of positions (^ and $).

    Something like that

    $vms = get-VM-location 'test '.

    for ($i = 0; $i - lt $vms. County; $i++)

    {

    $vmOS = get-View - ViewType 'VirtualMachine' - filter @{"Name" = "^ $($vms[$i].name)$" ""}-property @("Nom","Config.GuestFullName") |

    Select-Object - property name, @{N = "ConfiguredOS"; E={$_. Config.GuestFullName}}

    $vmOS

    }

  • Folder Get view filter VM


    Hello


    I have a script that get all the VM name and IP address on a specific vCenter and the VM naming convention, and it works like a charm. I would go more deep in the filter setting to be able to search in one specific folder.


    Is it possible to do with get-view?


    Here is my current get-view function:


    Notice-EEG - ViewType VirtualMachine-name of the property, Guest.HostName, Config.Hardware.Device, Guest.IPAddress - filter @{"Runtime.PowerState" ="PoweredOn"; "' the name '=' ^ BGSOFW ';


    Thanks for your help


    Manu

    Try something like this

    $folderName = "MyFolder"$tgtFolder = Get-Folder -Name $folderName
    
    Get-View -ViewType VirtualMachine -Filter @{"Parent"=$tgtFolder.ExtensionData.MoRef.Value} |Select Name
    

    The folder should be the folder where are virtual machines.

    In the case of nested folders, the script requires little additional code.

  • with Get-VIew-filter

    How can I search a host using its MoRef, code below does not work:

    Get-view viewtype - HostSystem-filter @ {"HostId"="host-139"}

    Luke,

    I was referring to the construction of the ManagedObjectReferen object.

    I wonder why you can not use the MoRef property. Maybe it's a bug.

    Can I use other moref properties, but NOT the property of MoRef

    The following example works:

    $v = get-view - ViewType virtualmachine-filter @{"runtime.host"="" ^ $host-2116 "}

    This wil return all virtual machines from the host-2116. The porperty runtime.host is of type ManagedObjectReference.

  • How to read the VM ProvisionedSpaceGB and UsedSpaceGB using get - view?

    Hello

    I would like to retrieve the properties of the VM ProvisionedSpaceGB and UsedSpaceGB using get - view and not get - vm.

    How do I do that?

    Thank you very much in advance!

    Kind regards

    André

    Hello, Andre-

    You can retrieve some properties of an object view VirtualMachine and then do some computed properties, such as:

    ## get the View object of this VM, with a choice few properties (faster), then select some info about the objectGet-View -ViewType VirtualMachine -Filter @{"Name" = "^myVM0$"} -Property Name,Summary.Storage |    Select Name,        @{n="ProvisionedSpaceGB"; e={($_.Summary.Storage.Committed + $_.Summary.Storage.Uncommitted) / 1GB}},        @{n="UsedSpaceGB"; e={$_.Summary.Storage.Committed / 1GB}}
    

    To just get these some properties in the call to Get-view is the smaller memory usage in the PowerShell session and much higher speed during the extraction of the View object (without specifying properties to retrieve, the cmdlet returns all properties). How does do for you?

  • Getting the data center of VirtualMachine with Get-View information

    Hello

    Y at - it a faster way to get the name of data using Get-View and the viewtype VirtualMachine Center.

    I found the following:

    Get-View -ViewType VirtualMachine -filter @{ "name" = "mtl1fsit02" } | Select-Object -Property Name,

    @{ Label = "GuestOSName"; Expression = { $_.summary.guest.guestfullname } },

    @{ Label = "Datacenter"; Expression = { (Get-view (Get-View (Get-view $_.parent).parent).Parent).name } }

    Thank you guys

    I think that the property calculated for the data center does not work in all situations.

    It assumes that your virtual machines are 3 levels down from the data center, which is not always the case.

    I personally use a loop, passing up through the parents, until he finds an object data center.

    something like that

    @{N = 'Center'; E = {}

    $parentObj = get-view $_. Parent

    While ($parentObj - isnot [VMware.Vim.Datacenter]({))

    $parentObj = get-view $parentObj.Parent

    }

    $parentObj.Name

    }

  • Use get - view to get the host data center

    Hey guys,.

    I'm trying to shoot the host number of name and the version with get-view.

    I got to that, but I also want to get the data center that host belongs to.

    How can I get that advice please, don't have Googling has not helped a lot.

    Thank you

    RJ

    With the ExtensionData property we have access to the object VirtualMachine .

    Most of the managed objects vSphere has a property, called Parent, which points to the object that is connected to our object (the ' mother' in other words).

    The content of the Parent property is a MoRef (pointer). To get the real object, we use the cmdlet Get-view with this MoRef.

    We repeat this process in a while loop until the parent object is an object of data center .

    It's a bit like the structure of the tree in the vSphere Client.

    You start with the ESX (i) server and back up in the tree until you encounter a data center.

  • MoRef filtered get - view

    Try to get resutlts an error

    PS > Get-View - ViewType property, Parent, MoRef hostsystem-name

    Get - view: 2011-02-08 08:46:35 Get-View

    Online: 1 character: 14

    + Get-view < < < < ViewType - hostsystem-name of the property, Parent, MoRef

    + CategoryInfo: NotSpecified: (:)) [Get-view], InvalidProperty)

    + FullyQualifiedErrorId: Client20_MoServiceImpl_GetNetInteropEntityView_ViError, VMware.VimAutomation.ViCore.Cmd

    ts.Commands.DotNetInterop.GetVIView

    I can still run and access.

    PS > (Get-View - ViewType hostsystem). MoRef

    Is there a way to specify this property which must be returned?

    Kind regards

    Ryan

    The command

    Get-view ViewType - hostsystem-name of the Parent property

    Returns an array if you have more than one host. This means that you must do something like:

    (Get-view ViewType - hostsystem-name of the Parent property) [0]. MoRef

    or

    $x = get - View - ViewType hostsystem-property name, Parent
    $x [0]. MoRef

    to retrieve the first host MoRef.

  • Get - VM to Get-View - viewtype VirtualMachine

    We want to replace our Get-VM with Get-View-viewtype VirtualMachine function, because it is a faster method.

    But for some reason, the output is not the same.

    You expect that they return both the same VirtualMachine object.

    Out with Get - VM:

    Name, PowerState, NUM CPUs, MemoryGB

    Out with Get-View - viewtype VirtualMachine:

    Capacity, Config, layout, LAyoutEx, storage,... all the VMware.Vim.VirtualMachine object.

    Our methods:

    $Hosts = get-VMsByLocation-site $Location

    $VMs = @)

    $Hosts | {ForEach}

    (A) $VMs += Get - VM $_

    (B) $VMs += Get-view -ViewType VirtualMachine - filter @{'Name' = $_}

    }

    https://www.VMware.com/support/developer/windowstoolkit/wintk40u1/HTML/get-VM.html

    https://communities.VMware.com/thread/474763

    https://www.VMware.com/support/developer/converter-SDK/conv50_apireference/Vim.virtualmachine.html

    https://pubs.VMware.com/vSphere-51/index.jsp#com.VMware.PowerCLI.cmdletref.doc/virtualmachine.html

    Hello, tendonsie-

    Yes, you are right: If you change the type of object that you are using, and then later call what's going used probably not work with .

    However, another part of the power of Get - view: you have direct access to a representation of the object "full" vSphere - the View .NET VirtualMachine object, in this case.  So, you do no need another call to get the CpuReservationMhz - you can get it directly from the object VirtualMachine who have already recovered you.  An example of include these goods in the output (based on the example I gave first):

    Get-View -ViewType VirtualMachine -Property Name,Runtime.PowerState,Config.Hardware,Config.CpuAllocation.Reservation | Select-Object Name,    @{n="PowerState"; e={$_.Runtime.PowerState}},    @{n="NumCPU"; e={$_.Config.Hardware.NumCPU}},    @{n="MemoryGB"; e={$_.Config.Hardware.MemoryMB / 1KB}},    @{n="CpuReservationMhz"; e={$_.Config.CpuAllocation.Reservation}}
    

    You see the additional calculated property, CpuReservationMhz, here.  Now you don't need even have call the Get-VMResourceConfiguration cmdlet.

    Thus, work comes to discover what are the properties of the View .NET object that you have recovered.  And this work is supported by the vSphere API documentation, a link that is available to VMware vSphere Web Services SDK Documentation.  How is that?

  • Using filters and Get - view to find virtual machines with a specific guest operating system.

    I have the following code snippet to find all virtual machines with the updated OS to ' Red Hat Enterprise Linux * "prompt. It does not work. If the filter is left out, I find myself with all virtual machines.

    The immediate question is the specs for the game ' Red Hat Enterprise Linux. " Originally from the "Performance Difference between GET - VM and GET-VIEW")

    http://www.batchworks.de/performance-difference-between-get-VM-and-get-view/ ).

    $ClusterFilter = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{“Name” = $ClusterName } | select -ExpandProperty MoRef

    $VirtualMachines = Get-View -ViewType VirtualMachine -Property Config -SearchRoot $ClusterFilter


    The biggest problem for me is to understand for Get-View filter. I was capable of a bit of insight to gleen from the URL below, but I think what Miss me is the reference (Microsoft) for what is happening to the right of the equal sign. What is the correct terminology for this type of query expression / where the syntax is 'left' = 'straight' and keywords such as "-match" are not allowed.

    http://purple-screen.com/?Cat=3

    VMware vSphere 5.1

    http://Wannemacher.us/?p=259

    Regular expressions with Windows PowerShell

    Right in the filter expression is an RegEx expression, please allow for characters before and after the word Linux.

    And the name of the OS is Config.GuestFullName.

    I corrected the entries more early as well.

    $ClusterName = "^MyCluster$"$ClusterFilter = get-view -ViewType ClusterComputeResource -Property Name -Filter @{"Name" = $ClusterName } | select -ExpandProperty MoRefWrite-Host $ClusterFilter
    
    $VirtualMachinesNoFilter   = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter $VirtualMachinesWithFilter = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter -Filter @{"Config.GuestFullName"=".*Linux.*"}
    
  • Problem combining Get - VM and Get-View

    I worked on a script for a while, and very close if he's working as I want.  The script below is what I have so far and works as I want.

    $(foreach ($cluster get-cluster) {get - view - viewtype VirtualMachine - SearchRoot $cluster.id | select @{N = 'The virtual computer name';}) E={$_. Name}}, @{N = "PowerState"; E={$_. Summary.Runtime.PowerState}}, @{N = "guest operating system"; E={$_. Config.GuestFullName}}, @{N = 'Cluster'; E = {$cluster. Name}}, @{N = 'Notes'; E={$_. Summary.Config.Annotation}}})

    However, I can't seem to shoot our custom annotations by using Get - view but can't Get - VM.  The script below works.

    Get - VM | Select Name, @{N = "Org1.Environment"; E = {(Get-Annotation-entité $_-CustomAttribute "Org1.Environment").} Value}}

    How to combine the two?  Any help would be greatly appreciated.

    Hello, Grimdari-

    You are pretty close to.  A couple of ways you could do this, the first using the code of Get-Annotation you did already:

    foreach ($cluster in Get-Cluster) {    Get-View -ViewType VirtualMachine -SearchRoot $cluster.id | Select @{n="VM name"; e={$_.Name}},        @{n="PowerState"; e={$_.Summary.Runtime.PowerState}},        @{n="Guest OS"; e={$_.Config.GuestFullName}},        @{n="Cluster"; e={$cluster.name}},        @{n="Notes"; e={$_.Summary.Config.Annotation}},        ## using the Get-VIObjectByVIView cmdlet; slower        @{n="Org1.Environment"; e={(Get-Annotation -Entity (Get-VIObjectByVIView $_) -CustomAttribute "Org1.Environment").Value}}} ## end foreach
    

    And the second, stick with the info you've already recovered in the call to Get-View :

    ## selected properties to retrieve in Get-View call$arrViewPropertiesToGet = "Name","Summary.Runtime.PowerState","Config.GuestFullName","Summary.Config.Annotation","CustomValue","AvailableField"foreach ($cluster in Get-Cluster) {    Get-View -ViewType VirtualMachine -Property $arrViewPropertiesToGet -SearchRoot $cluster.id | Select @{n="VM name"; e={$_.Name}},        @{n="PowerState"; e={$_.Summary.Runtime.PowerState}},        @{n="Guest OS"; e={$_.Config.GuestFullName}},        @{n="Cluster"; e={$cluster.name}},        @{n="Notes"; e={$_.Summary.Config.Annotation}},        ## just using the data already retrieved; far faster        @{n="Org1.Environment"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Org1.Environment"}).Key}).Value}}} ## end foreach
    

    The second way is much faster, though it might be a little less obvious how she came up with the results.  He becomes the value of CustomValue where CustomValue key corresponds to the key AvailableField for the AvailableField with the name of the attribute you want.  Anyway, how those who do for you?

  • Cannot delete a file in windows 7. Indicates the specified file name is not valid or too long.

    Hello everyone, I'm pretty stuck here. I can't delete a file in windows 7 or any other do with it besides. Says "the specified file name is not valid or too long. It has a funny name [~ t] and no extension. The file type, say "file". The properties are all screwed looking with a mistake on the Security tab, a size of 0 k, is a Windows (c) \Windows\en-US.The other files in this folder appear normal. The computer seems to work very well without any obvious problems. The only problem is my anti-virus reports with a kind of syntax for the file error and indicates it cannot parse this file. I do not. I can't do a thing with it either. Cannot open, rename, move, delete, change passwords, properties, permissions, nothing. It may be necessary for a good part with 0kb. According to me, I want to just delete the thing. Please, anyone? Thanks in advance.

    Hey bud, I figured out how fix it earlier. I am so happy. I came to remember a command called chkdsk which worked very well for various issues, that I had since the construction of my old 2000 Professional machine. I think that one was my first NTFS system. I always liked how well he error correction. Seemed a lot better than the old scandisk. Low and behold, I tried and star ANISE, it is went through it, found this file almost from the beginning of the analysis and a few lines later, he said has been removed. Says something about the file being orphaned some time ago. It was a very bad child, that I tell you. I ran it in safe mode command prompt. I guess he would have done the same thing in the normal windows well, but I happened to be in safemode, when it came to me. I used the switch /f with her. Since the C:\ command prompt or any drive letter your operating system is selected, type CHKDSK/F if I remember although the f was to have it automatically CORRECT errors. I hope this info helps others with their file or disk problems. It seems that many people say they get mistakes and cannot delete various files here in these forums. Thanks Sandeep for answering me and try to help. It does not matter whether or not it was the fix, it takes time to post and your helping people learn to be it. The only thing that remains unanswered for me is actually the thing of the answer. I mean I can't say someone at - it really answered my question and do not count me? Maybe I should mark so that people will bother to read it and get the fix. HMMMM... I come back here some time later and see whats up.  SeeYou, EWOO

  • How to run a job Disqualification with the ability to specify the name of the file to process

    Hello

    We want to start a task from the Disqualification by command line where I can specify the name of the input in the command line file?

    I tried to use the Externalize in drive and renamed the 'enable' file name and try to use the command below.

    > java-jar jmxtools.jar runopsjob-ProcessFileToLoad of the job-project DataLoad u weblogic Pei welcome123 - runlabel Jul24 d FileName = abc.dat - nowait localhost:8090

    I expect this command will take the entrance as abc.dat instead which is specified as a reader in the work process. But it does not have the file specified as input and still treat the work with the original staging data.

    Please help how I can use several files get handled by using the unique task.

    Thank you
    Ravi

    Hi Ravi,

    The syntax for the outsourced options is the same as in execution profiles, would be if:

    D - phase.*.snapshot. *. FileName = abc.dat

    Assuming you outsourced or not ownership of file name as "filename."

    Kind regards

    Nick

Maybe you are looking for