Calling Code ?
Posted: Fri Jan 12, 2018 2:10 pm
Product, version and build: 5.4.145
32 or 64 bit version of product: 64
Operating system: Windows 10, Windows 7
32 or 64 bit OS: Both
I have a PowerShell Studio tool that has a field for "computer name" once you enter a computer name you can then press many different buttons on different forms that will execute code against that computer name. I have this code that works as expected but I have to copy/paste it into many many different parts of my overall script as part of any button that runs code against the computer.
if ($PC -eq "" -OR $PC -like " ")
{
$Error1 = "You did not enter a machine in the computer field."
$richtextbox_Output.Clear()
$richtextbox_Output.SelectionColor = 'Red'
$richtextbox_Output.appendtext($Error1)
}
Is there a way to use this code over and over when you want? Can I declare it in some way within PowerShell studio? Or.....can it only work if it is a Function?
I was trying to envision something like this:
$ERRORCODE = "my code from above"
Then I can just call $ERRORCODE when I want and it will execute.
32 or 64 bit version of product: 64
Operating system: Windows 10, Windows 7
32 or 64 bit OS: Both
I have a PowerShell Studio tool that has a field for "computer name" once you enter a computer name you can then press many different buttons on different forms that will execute code against that computer name. I have this code that works as expected but I have to copy/paste it into many many different parts of my overall script as part of any button that runs code against the computer.
if ($PC -eq "" -OR $PC -like " ")
{
$Error1 = "You did not enter a machine in the computer field."
$richtextbox_Output.Clear()
$richtextbox_Output.SelectionColor = 'Red'
$richtextbox_Output.appendtext($Error1)
}
Is there a way to use this code over and over when you want? Can I declare it in some way within PowerShell studio? Or.....can it only work if it is a Function?
I was trying to envision something like this:
$ERRORCODE = "my code from above"
Then I can just call $ERRORCODE when I want and it will execute.