Forum Discussion
ADumith
Dec 16, 2021Iron Contributor
Working with functions
Hello everyone!
I have a script that has three processes and I want to create a function for each process and then from the same script call each function. Is that possible? How do I do it?
Example:
$computers=@('a','b','c','d','e')
ForEach ($pc in $computers)
{
ClossingApps -ComputerName $pc
RemovingApps -ComputerName $pc
InstallingApps -ComputerName $pc
}
function ClossingApps {
param (
$ComputerName
)
Write-Output "Closing"
}
function RemovingApps {
param (
$ComputerName
)
Write-Output "Removing"
}
function InstallingApps {
param (
$ComputerName
)
Write-Output "Installing"
}
Thank you
Hi ADumith
don't forget to call the functions, because RATM, you just defined them.
https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7.2
function Start-Calculator{ start calculator.exe } start-calulator #The actual function startBest regards Schnittlauch
1 Reply
- SchnittlauchIron Contributor
Hi ADumith
don't forget to call the functions, because RATM, you just defined them.
https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7.2
function Start-Calculator{ start calculator.exe } start-calulator #The actual function startBest regards Schnittlauch