sns 8,116 Reputation points

I want to open some of the processes with the help of function, But I saw below warning which I am not quite sure, Please assist
and Also what I should do to use this function every time when I log in ISE ( not only for current session, I need for all sessions )

Please help


Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,731 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 24,701 Reputation points

    You should start by downloading and reviewing this document.

    Powershell can use positional parameters or named parameters.

    function TestPosition ($ProcessName,$SomethingElse) {
        Write-Host ""
        Write-Host "You asked me to look for $ProcessName." 
        Write-Host "And do something with $SomethingElse." 
        Get-Process $ProcessName
    function TestNamed {param (
            [string]$ProcessName = "",
            [string]$SomethingElse = ""
        Write-Host ""
        Write-Host "You asked me to look for $ProcessName." 
        Write-Host "And do something with $SomethingElse." 
        Get-Process $ProcessName
    TestPosition "notepad" "foo"
    TestNamed -SomethingElse "XXXXXX" -ProcessName "Powershell"
  2. Limitless Technology 37,506 Reputation points

    Hi there,

    There are many ways to handle errors in Windows PowerShell, including:

    $Error.Clear(); Do-Something; If ($Error) {..} Else {..}

    Trap blocks generally catch any errors in the scope of the entire script or function. The beauty of Try, Catch, Finally is that it is like a localized Trap for a specific block of commands. This gives you great flexibility in your error handling.

    Here are some links to help you out

    Using Try, Catch, Finally Blocks for PowerShell Error Handling

    Handling Errors the PowerShell Way

    --If the reply is helpful, please Upvote and Accept it as an answer--