Powershell Variable data from Functions being lost -
I am trying to create a script and the way I am collecting data in a $ message variable.
The first line in my script is:
$ message = "Verifying the server is running on the server" $ ComputerName " And this is all that is output.
I have in my functions: startervice = start-service $ license $ message + = "$ savannah The " function works to start when the message is not running, while it does not attach the message to the $ message variable, when used in a loop, for example Eg ($ Servicename in $ services) {FuncCheckService $ ServiceName}
What can I do to collect data in my variable?
This is because the function works in a different workspace than the rest of the script. What you might want to do is change the last line to the following:
write-output "$ message $ service name" attempt to start Only when you can call the function:
$ message = startaservicefunction and then captures any output from the $ message function , Which will be the message you want to pass.
Or just do not have a function that is running and is trying to start, and run it like $ message + = function:
$ current service = Start-up service $ write service name-Output "Trying to start $ Savannium is not going to start" $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Alternatively, and I do not recommend doing this when you can do it in the context of global variables while updating it Are: $ global: Message + = "$ ServiceName attempting to start is not running" This will update the $ message variable outside of it.
Comments
Post a Comment