I have a Windows PowerShell 3.0 script with a workflow and 2 simple functions. Without the workflow I can use my Log
function inside my DoSomething
function but with the workflow I cannot. The script is:
function DoSomething()
{
# This is NOT logged
Log("This will fail...")
}
function global:Log([string]$Message)
{
Add-Content -Path "C:\my.log" -Value $Message
}
workflow New-CustomWorkflow
{
try
{
# This is logged
Log("Starting with the workflow")
DoSomething
}
catch
{
# This is logged
Log($_)
}
}
New-CustomWorkflow
The content of my.log
looks like this:
Starting with the workflow
System.Management.Automation.RemoteException: The term 'Log' 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.
at Microsoft.PowerShell.Activities.PSActivity.OnResumeBookmark(NativeActivityContext context, Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkCallbackWrapper.Invoke(NativeActivityContext context, Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
Is this possible? What am I doing wrong?