0

The term 'AutomatedTest' is not recognized is a name of cmdlet......

but I don't know why.

But Powershell ISE works,

Function as below

if($DefaultPool.GetMachines().Name -eq $TestMachineOne)
 {
   MultiMachineTest
 }else{
   AutomatedTest
 }

function AutomatedTest()
{
   Write-host "test"
}
1
  • 3
    Move your function definition before your call. It works in ISE because you've already run your script, so the functions in memory from the previous run. Commented Aug 4, 2017 at 10:03

1 Answer 1

1

Add your function at the top of your script so that it's loaded before executing it.

function AutomatedTest()
{
   Write-host "test"
}

if($DefaultPool.GetMachines().Name -eq $TestMachineOne)
    {
       MultiMachineTest
    }else{
        AutomatedTest
    }
Sign up to request clarification or add additional context in comments.

2 Comments

but I follow this , is no response, not write host test
if there is no response, it's because $DefaultPool.GetMachines().Name not equals $TestMachineOne. Reverse your 2 functions in the condition and see what happens.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.