# Stupid question I suppose

**URL:** <https://forums.powershell.org/t/stupid-question-i-suppose/3734>\
**Category:** PowerShell Help\
**Created:** [February 10, 2015, 8:21am UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734 "2015-02-10T08:21:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael-swann](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@michael-swann](https://forums.powershell.org/u/michael-swann)\
**Post date:** [February 10, 2015, 8:21am UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/1 "2015-02-10T08:21:30Z")

</div>

$Vms = Get-VM

ForEach ($Vm in $Vms) {  
$Vm.GetType()  
}

I never have understood how the singular variable ‘$VM’ gets its value?

---

<div class="post-metadata">

**Author:** ![adnan-rashid](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@adnan-rashid](https://forums.powershell.org/u/adnan-rashid)\
**Post date:** [February 10, 2015, 8:27am UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/2 "2015-02-10T08:27:37Z")

</div>

The variable $vms will contain a collection of virtual machines.

The next line is saying foreach virtual machine in the collection of machines execute the bit of code within the brackets.

You now want to reference $vm because we are referencing a single machine within that collection. It wouldnt make sense to say $vms because thats the whole collection.

Hope that made some sense?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [February 10, 2015, 8:31am UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/3 "2015-02-10T08:31:03Z")

</div>

It’s what the ForEach construct does for a living.

Variable 2 has one or more objects; one at a time is taken and put into variable 1. That’s literally what ForEach is doing, and that’s how it happens. Nearly all programming languages have an equivalent construct.

---

<div class="post-metadata">

**Author:** ![greg-altman](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/greg-altman/32/665_2.png) [@greg-altman](https://forums.powershell.org/u/greg-altman)\
**Post date:** [February 10, 2015, 8:43am UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/4 "2015-02-10T08:43:05Z")

</div>

So… to look at it a different way…  
The line could read  
`ForEach ($XYZ in $Vms)`  
and work the same yes?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [February 10, 2015, 8:49am UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/5 "2015-02-10T08:49:49Z")

</div>

Yes, absolutely. PowerShell doesn’t assign any semantic meaning to variable names. You’d use $VM and $VMs because it helps you keep track, not because PowerShell cares. In fact, I use almost that exact explanation in Learn PowerShell in a Month of Lunches, because thinking the plural vs. singular variable names are important is a huge hangup for a lot of beginners… in any programming language, not just PowerShell.

---

<div class="post-metadata">

**Author:** ![michael-swann](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@michael-swann](https://forums.powershell.org/u/michael-swann)\
**Post date:** [February 12, 2015, 3:11pm UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/6 "2015-02-12T15:11:12Z")

</div>

I thank all for the response. The problem with anything is doing and doing it more. I want to master powercli. I am learning quick that to do so requires mastering Powershell.

This is the first time I have been excited about learning Microsoft technology! Powershell is really the greatest thing that Microsoft has developed since WINXP. I really want to use powershell as a means to have a deeper understanding of the underlying windows technology.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/stupid-question-i-suppose/3734/7 "2024-05-16T20:46:22Z")

</div>


