Solved

# What is wrong with this for loop?

Posted on 2013-01-22
461 Views
I am trying to find the state a a list of vms with this for loop:

$VM = get-content C:\Users\PowerShell\left_overs.txt foreach ($PC in $VM) { get-vm }  Instead of giving me the list of the few VMs in the list it gives me everything in vsphere... any ideas why this is not working? 0 Question by:Thaidog • 3 • 2 • 2 7 Comments LVL 35 Accepted Solution Joseph Daly earned 500 total points ID: 38807238 Your not passing the -name parameter to your GET-VM command. Try this.$VM = get-content C:\leftovers.txt
foreach ($computer in$VM) {
get-vm -name $computer } 0 LVL 40 Expert Comment ID: 38807310$VM = get-content C:\Users\PowerShell\left_overs.txt
foreach ($PC in$VM) { get-vm $PC} and Get-content C:\Users\PowerShell\left_overs.txt | get-vm Should also work.. 0 Author Comment ID: 38807358 The first worked - thanks! The second I got an error: "Cannot process argument transformation parameter 'Datastore'. Strings as pipeline input are not supported." 0 LVL 40 Expert Comment ID: 38807374 Then Try.. Get-content C:\Users\PowerShell\left_overs.txt | % {get-vm$_}

0

Author Comment

ID: 38810412
Did not work:

PS C:\Users\> Get-content C:\Users\SkyDrive\PowerShell\left_overs.txt | % {get-vm $_} Get-VM : 1/23/2013 10:33:23 AM Get-VM VM with name 'Server1 on' was not found using the specified filter( s). At line:1 char:77 + Get-content C:\Users\SkyDrive\PowerShell\left_overs.txt | % {get-vm <<<<$_}
+ CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM


(Edit: Redacted - Modulus_Twelve)
(http://www.experts-exchange.com/R_20923.html)
0

LVL 40

Expert Comment

ID: 38810452

(Edit: Redacted - Modulus_Twelve)
(http://www.experts-exchange.com/R_20923.html)
0

LVL 35

Expert Comment

ID: 38810453
If my solution worked why are you still looking for another answer?
0

## Featured Post

### Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…