Assume I have the following PS Script myscript.ps1:
param(
[string]$ID
)
Write-Host "Step 1 $ID"
Write-Host "Step 2 $ID"
# Inject some custom step here
Write-Host "Step 3 $ID"
That I call from another PS script with
$ [path]\myscript.ps1 -ID 001
$ [path]\myscript.ps1 -ID 002
$ [path]\myscript.ps1 -ID 003
Now when I run the last call:
$ [path]\myscript.ps1 -ID 003
I would like to trigger some custom behavior/steps just after:
Write-Host "Step 2 $ID"
in myscript.ps1. I considered this:
$ [path]\myscript.ps1 -ID 001
$ [path]\myscript.ps1 -ID 002
$ [path]\myscript.ps1 -ID 003 -customScript "[path]\custom.ps1"
and then update myscript.ps1 to:
param(
[string]$ID,
[string]$custom=""
)
Write-Host "Step 1 $ID"
Write-Host "Step 2 $ID"
if($custom) {
& $custom
}
# Inject some custom step here
Write-Host "Step 3 $ID"
Maybe there are some more elegant way of doing this?
I have looked at: http://blogs.msdn.com/b/powershell/archive/2008/06/11/powershell-eventing-quickstart.aspx
but it does not really seem to fit the purpose.