SOLVED

Working with functions

Contributor

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

1 Reply
best response confirmed by ADumith (Contributor)
Solution

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 start

Best regards Schnittlauch