 <p>This is because the function works in a separate workspace than the rest of the script. What you may want to do is change that last line to:</p> <pre><code>Write-Output "$message$ServiceName is not running attemting to start" </code></pre> <p>Then when you call the function you can do:</p> <pre><code>$Message = StartServiceFunction </code></pre> <p>And then $Message captures any output from the function, which would be the message you wanted to pass.</p> <p>Or just have the function pass the service that isn't running and attempting to start, and run it as $Message += Function such as:</p> <pre><code>$startservice=Start-Service $ServiceName Write-Output "$ServiceName is not running attemting to start" ForEach($servicename in $services) { $Message += FuncCheckService $ServiceName } </code></pre> <p>Alternatively, and I wouldn't recommend doing it this way, you could reference the global variable instead when you update it:</p> <pre><code>$global:message+="$ServiceName is not running attemting to start" </code></pre> <p>That will update the $message variable outside of the function.</p>