Please provide detail in your response on how you answered the question so that I can maybe understand it for myself.
Thank you in advance for any help.
***************************************...
MY TASK
-Write a script that prints out the first 100 multiples of 2
You must use a for loop or while loop
-Write a script that retrieves a collection of objects (an array), loops through them, and displays one property (your choice) of the object with the Write-Host cmdlet
You must use a for loop or while loop
***************************************...
I believe I figured out the first question using this command in powershell.
$a = 2
$b = 1
$c = $a * $b
write-host "Here are the first 100 multiples of 2.`n`nStarting at 2x1 and ending at 2x100"
do
{
write-host
$a * $b
$b++
$c = $a * $b
}while($c -ne 202)
That seems to work, but let me know if I am completely wrong.
The other question is where I am completely lost.
Your script works, but can be shortened and simplified. Have a look in the documentation for examples of how to use for and while:
As for your second task, you can retrieve a collection of objects using for instance Get-Process. Use dot notation or Select-Object to get properties from objects. You will need to find the count of objects in your collection to use in your loop.
One last tip is to write your script in PowerShell ISE. Good luck ;)
- Proposed as answer by AnnaWYMicrosoft contingent staff, Moderator 4 hours 37 minutes ago
Your script works, but can be shortened and simplified. Have a look in the documentation for examples of how to use for and while:
As for your second task, you can retrieve a collection of objects using for instance Get-Process. Use dot notation or Select-Object to get properties from objects. You will need to find the count of objects in your collection to use in your loop.
One last tip is to write your script in PowerShell ISE. Good luck ;)
- Proposed as answer by AnnaWYMicrosoft contingent staff, Moderator 4 hours 45 minutes ago
Your write-host is not doing anything. The loop also does nothing. You have not read the instruction correctly. It wants a annray of objects to work on. You are juust loopin on nothing.
Here is a hint:
# array here; $a=1..100 # loop on array foreach($x in $a){ write-host "X is $x and X times 2 is $($x * 2 )" -fore green }
The purpose of this in college is not to turn you into a programmer but to teach you how to think like a human being. You are clearly in need to this challenge as you have not given this any though. T+YOU start with a lame disclaimer and then expect others to do the thinking for you. YOu will not get a good job with that approach. Try engaging your brain. It will shrivel with lack of use.
Your script works, but can be shortened and simplified. Have a look in the documentation for examples of how to use for and while:
As for your second task, you can retrieve a collection of objects using for instance Get-Process. Use dot notation or Select-Object to get properties from objects. You will need to find the count of objects in your collection to use in your loop.
One last tip is to write your script in PowerShell ISE. Good luck ;)
- Proposed as answer by AnnaWYMicrosoft contingent staff, Moderator Monday, June 29, 2015 2:24 AM
Your script works, but can be shortened and simplified. Have a look in the documentation for examples of how to use for and while:
As for your second task, you can retrieve a collection of objects using for instance Get-Process. Use dot notation or Select-Object to get properties from objects. You will need to find the count of objects in your collection to use in your loop.
One last tip is to write your script in PowerShell ISE. Good luck ;)
- Proposed as answer by AnnaWYMicrosoft contingent staff, Moderator Monday, June 29, 2015 2:24 AM
Your write-host is not doing anything. The loop also does nothing. You have not read the instruction correctly. It wants a an array of objects to work on. You are just looping on nothing.
Here is a hint:
# array here; $a=1..100 # loop on array foreach($x in $a){ write-host "X is $x and X times 2 is $($x * 2 )" -fore green }
The purpose of this in college is not to turn you into a programmer but to teach you how to think like a human being. You are clearly in need to this challenge as you have not given this any though. You start with a lame disclaimer and then expect others to do the thinking for you. You will not get a good job with that approach. Try engaging your brain. It will shrivel with lack of use.
Thank you so much I really appreciate it. Yes at first I was using notepad to type my scripts. And then I learned about ISE. That is 1000 times better, I love it.
Thanks again.
Thank you so much I really appreciate it. Yes at first I was using notepad to type my scripts. And then I learned about ISE. That is 1000 times better, I love it.
Thanks again.
Wonderful. We love this. You should consider this as a career.