I execute a PowerShell script to create folders and inbox-rules in Office365.
The script works fine when called from SQL Server.
But if I put the code in function and calls with Start-Job then it stops working from SQL Server - but it will work if executed from local machine(?)
I really want code to run in background because it takes 2-3 minutes to complete.
Any suggestions as to what I'm doing wrong?
This is code that works from SQL Server:
param(
[Parameter(Position=0, Mandatory=$true)] [string]$FolderName
)
-- CODE HERE --
-- End of file
This is my code with ScriptBlock (does not work from sql, but works from local machine/server):
param(
[Parameter(Position=0, Mandatory=$true)] [string]$FolderName
)
$func = {function createFolderAndRule {
param([string]$FolderName)
#-- CODE HERE --
}
}
Start-Job -ScriptBlock {param($tm) createFolderAndRule $tm } -InitializationScript $func -ArgumentList($FolderName)
# End of file