I want to know how I can run a PowerShell script that I´ve created as a project global script in FinalBuilder by means of action Execute PowerShell Script?
This is the function I´ve created and that I want to call in the "Script" tab of the above mentioned action:
function Get-ComputerName { Get-Content Env:COMPUTERNAME }
Unfortunately I did not find any answer to this question in the online help. Can anybody help?
Just use the Run Script action, and call the function as you would any other function. You cannot call project global script functions from external scripts or the Execute Powershell script action.
One thing is still not working. If I want to remotely invoke a project global powershell script, I used the following code in the "Run Script" action on tab "OnExecute"
Get-ComputerName is a project global script containing this code block
function Get-ComputerName { Get-Content Env:COMPUTERNAME }
Running this action result in the following error message
The term 'Get-ComputerName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. + CategoryInfo : ObjectNotFound: (Get-ComputerName:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
If I replace the call to the globally defined function by the function body, the action runs fine.
To get this to work in my case, I simply had to replace the curly braces with parentheses. i.e: Invoke-Command -computerName $DeploymentServer -scriptBlock ( Get-ComputerName )
Could you please try this and confirm whether this works for you?
Sorry, I overlooked part of your previous post. The problem is here that the script block argument needs to contain script that can be executed on the target machine. In this case you are passing in a function that is inaccessible to the remote machine, which is causing it to fail.
If you change your command to the following it will work (removing the reference to the global function): Invoke-Command -computerName $DeploymentServer -scriptBlock { Get-Content Env:COMPUTERNAME }
Global functions are only able to be used within the scope of FinalBuilder script events.
I was afraid that you would say that. As you can see from my previous post, this was what I have tried before. But anyway, thank very much for your help.