How would I make powershell accept more than one input? For example, let’s say I want to add 1+2 so I have $one and $two, but sometimes it could be 1+2+3? How would I do this?
Let’s say I have a text file like this:
zero
one
two
three
How would I set and save lines one through two [1…2] to be blank so that it’s?
zero
three
Is there any professional PowerShell schools that I can go to learn more or is books and videos the best method to learn?
For question 1, one way to do that would be to create a function with a parameter, and make that parameter accept multiple values, and then itterate over that parameter.
Example:
function Add-Numbers {
Param(
[Parameter(Mandatory = $true)]
[Int[]] # <-- The extra [] make the parameter accept an array of input
$Numbers
)
foreach ($num in $Numbers)
{
$result += $num
}
Write-Output $result
}
Add-Numbers -Numbers 1,2,3
And for question 3, I recommend watching the free PowerShell content on Microsoft Virtual Academy. “Getting Started with Microsoft PowerShell” is a good starting point. When it comes to books, the “Learn Windows PowerShell in a Month of Lunches” and “Learn PowerShell Toolmaking in a Month of Lunches” books are good reads. Additionaly Pluralsight have a lot of PowerShell courses as well.
Question 3 has been asked several times already here and in other forums like Microsoft Forum for Powershell. You’re welcome to use the search function of these forums or even google.