Cancelado

Powershell/SQL run script in background

This is the sql trigger:

BEGIN --SP

declare @cmd nvarchar(2000)

declare @folder nvarchar(200)

SET @folder = ''''+'"'+(SELECT CAST(Project_ID as nvarchar)+' '+Name FROM Project WHERE Project_ID=@projID)+'"'+''''

set @cmd = 'powershell "D:\PS\[url removed, login to view]"'+' ' +@folder

exec master.dbo.xp_cmdshell @cmd

END --SP

This is script that works when called from sql but takes very long to finish:

param(

[Parameter(Position=0, Mandatory=$true)] [string]$FolderName

)

$username = "mg@[url removed, login to view]"

$PasswordFile = "D:\PS\Passwords\[url removed, login to view]"

$KeyFile = "D:\PS\Passwords\[url removed, login to view]"

$key = Get-Content $KeyFile

$UserCred = New-Object [url removed, login to view] ($username, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key))

$NetWorkCred = New-Object [url removed, login to view]($username , (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key))

$Session = New-PSSession -ConfigurationName [url removed, login to view] -ConnectionUri [url removed, login to view] -Credential $UserCred -Authentication Basic -AllowRedirection

Import-Module D:\PS\[url removed, login to view]

Create-Folder -MailboxName prosjekt@[url removed, login to view] -Credentials $NetWorkCred -NewFolderName $FolderName -ParentFolder '\Innboks'

Import-PSSession $Session

$ProjectNo = $[url removed, login to view](0,4)

New-InboxRule -Name $ProjectNo -Mailbox prosjekt@[url removed, login to view] -SubjectOrBodyContainsWords "PREFAB$ProjectNo" -MoveToFolder ":\Innboks\$FolderName" -StopProcessingRules $true -confirm:$false -Force

Remove-PSSession $Session

This is script that works when executed locally on server and works in background, but it does not work when called from sql trigger:

param(

[Parameter(Position=0, Mandatory=$true)] [string]$FolderName

)

$createFolderAndRule = {

param([string]$FolderName)

$username = "mg@[url removed, login to view]"

$PasswordFile = "D:\PS\Passwords\[url removed, login to view]"

$KeyFile = "D:\PS\Passwords\[url removed, login to view]"

$key = Get-Content $KeyFile

$UserCred = New-Object [url removed, login to view] ($username, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key))

$NetWorkCred = New-Object [url removed, login to view]($username , (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key))

$Session = New-PSSession -ConfigurationName [url removed, login to view] -ConnectionUri [url removed, login to view] -Credential $UserCred -Authentication Basic -AllowRedirection

Import-Module D:\PS\[url removed, login to view]

Create-Folder -MailboxName prosjekt@[url removed, login to view] -Credentials $NetWorkCred -NewFolderName $FolderName -ParentFolder '\Innboks'

Import-PSSession $Session

$ProjectNo = $[url removed, login to view](0,4)

New-InboxRule -Name $ProjectNo -Mailbox prosjekt@[url removed, login to view] -SubjectOrBodyContainsWords "PREFAB$ProjectNo" -MoveToFolder ":\Innboks\$FolderName" -StopProcessingRules $true -confirm:$false -Force

Remove-PSSession $Session

}

Start-job -ScriptBlock $createFolderAndRule -Argumentlist $FolderName

Habilidades: Powershell, SQL

Ver más: run sql script inno setup, inno setup run sql script, joomla run sql script, php run sql script shared sever, run sql script zen cart, run sql script output back, perl script run sql, iis run background script job, run jobs background script linux, run sql procedure perl script, run sql script automatically phpmyadmin, mysql script run background, run sql server 2005 script, console application run sql 2005 script, run sql commands perl script simple

Información del empleador:
( 5 comentarios ) Bjerkreim, Norway

ID de proyecto: #11656214

3 los freelancers están ofertando un promedio de €372 para este trabajo.

TechyMonkey

Hi. We are ready to do this for you as per your requirement. You can check the reviews and can make out that we only do quality work. We are very sure that we will earn your 5 star review for this project. Looking for Más

€400 EUR en 7 días
(0 comentarios)
0.0
infusionsoft2

Dear Prospect Hiring Manager. Thank you for giving me a chance to bid on your project. I am a serious bidder here and i have already worked on a similar project before and can deliver as u have mentioned I have c Más

€555 EUR en 10 días
(0 comentarios)
0.0
work0786

We have 12 Years Experienced in PHP, HTML, CSS, MySQL, Wordpress, Apache, Server .Net ( C# and Vb.Net ) Android & IOS etc am really good at fixing errors and bugs. I always think outside the box to provide the best Más

€555 EUR en 10 días
(0 comentarios)
0.0
OrangeTechsol

Hello Sir, I understood that you are looking for Experienced SQL developer. Can you please share your best time for the chat so we can discuss further and move ahead. We have team of experienced DBA/Develope Más

€311 EUR en 5 días
(0 comentarios)
0.0
xielessupport

I can make your project a great success. I'm 31 year old talented PHP and open-source developer. I have 9 years of experience in Server Administration and Web Application Development. I'm expert in web application cust Más

€404 EUR en 12 días
(0 comentarios)
0.0