Find Jobs
Hire Freelancers

Fix bug in powershell script executed from Sql server

€8-30 EUR

Preklicano
Objavljeno pred več kot 7 leti

€8-30 EUR

Plačilo ob dostavi
I have a sql trigger that executes a ps1 script. The script works but I would like to have it work in background. Takes very long to finish. When I try to set it up as a script block it only works when executed locally from server. Not when executed from Sql Server: This is the sql trigger: ------------------- declare @cmd nvarchar(2000) declare @folder nvarchar(200) SET @folder = ''''+'"'+(SELECT CAST(Project_ID as nvarchar)+' '+Name FROM INSERTED)+'"'+'''' set @cmd = 'powershell "D:\PS\[login to view URL]"'+' ' +@folder exec master.dbo.xp_cmdshell @cmd ------------------------- This is script that works when called from sql but takes very long to finish: ------------------------- param( [Parameter(Position=0, Mandatory=$true)] [string]$FolderName ) $username = "user" $PasswordFile = "D:\PS\Passwords\[login to view URL]" $KeyFile = "D:\PS\Passwords\[login to view URL]" $key = Get-Content $KeyFile $UserCred = New-Object [login to view URL] ($username, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)) $NetWorkCred = New-Object [login to view URL]($username , (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)) $Session = New-PSSession -ConfigurationName [login to view URL] -ConnectionUri [login to view URL] -Credential $UserCred -Authentication Basic -AllowRedirection Import-Module D:\PS\[login to view URL] Create-Folder -MailboxName mailbox -Credentials $NetWorkCred -NewFolderName $FolderName -ParentFolder '\Innboks' Import-PSSession $Session $ProjectNo = $[login to view URL](0,4) New-InboxRule -Name $ProjectNo -Mailbox mailbox -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 = "user" $PasswordFile = "D:\PS\Passwords\[login to view URL]" $KeyFile = "D:\PS\Passwords\[login to view URL]" $key = Get-Content $KeyFile $UserCred = New-Object [login to view URL] ($username, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)) $NetWorkCred = New-Object [login to view URL]($username , (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key)) $Session = New-PSSession -ConfigurationName [login to view URL] -ConnectionUri [login to view URL] -Credential $UserCred -Authentication Basic -AllowRedirection Import-Module D:\PS\[login to view URL] Create-Folder -MailboxName mailbox -Credentials $NetWorkCred -NewFolderName $FolderName -ParentFolder '\Innboks' Import-PSSession $Session $ProjectNo = $[login to view URL](0,4) New-InboxRule -Name $ProjectNo -Mailbox mailbox -SubjectOrBodyContainsWords "PREFAB$ProjectNo" -MoveToFolder ":\Innboks\$FolderName" -StopProcessingRules $true -confirm:$false -Force Remove-PSSession $Session } Start-job -ScriptBlock $createFolderAndRule -Argumentlist $FolderName -------------------------
ID projekta: 11656683

Več o projektu

7 ponudb
Projekt na daljavo
Aktivno pred 8 leti

Želite zaslužiti?

Prednosti oddajanja ponudb na Freelancerju

Nastavite svoj proračun in časovni okvir
Prejmite plačilo za svoje delo
Povzetek predloga
Registracija in oddajanje ponudb sta brezplačna
7 freelancerjev je oddalo ponudbo s povprečno vrednostjo €51 EUR za to delo
Avatar uporabnika
Hi, This can't be done using MySQL, because xp_cmdshell command will block execution and wait for the program to finish. The proper way to do this is detect the condition of trigger,enque the data to be processed in a table, and have a program run in such a way that it polls the table for the data and then use it for the processing. for further information,please contact me. regards, Tarandeep
€28 EUR v 1 dnevu
5,0 (6 ocen)
2,9
2,9
Avatar uporabnika
Dear Project Poster, I have relevant hands on 5 years of experience .We have a team of all the skills. I assure you about the work quality and time delivery. Please give me chance to complete this project. We have 100% client satisfaction ratio. I had already done the same work in past. Looking forward to hear from you. Let me give an opportunity to work. We can talk further when you message me.
€33 EUR v 1 dnevu
0,0 (0 ocen)
0,0
0,0
Avatar uporabnika
Hello. first of all check which account uses SQL when triggering. Usually this is issue source. In case of any questions feel free to chat. Thanks and have a nice day.
€55 EUR v 1 dnevu
0,0 (0 ocen)
0,0
0,0

O stranki

Zastava NORWAY
Bjerkreim, Norway
4,8
5
Plačilna metoda je verificirana
Član(ica) od avg. 20, 2016

Verifikacija stranke

Hvala! Po e-pošti smo vam poslali povezavo za prevzem brezplačnega dobropisa.
Pri pošiljanju vašega e-sporočila je šlo nekaj narobe. Poskusite znova.
Registrirani uporabniki Skupaj objavljenih del
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Nalaganje predogleda
Geolociranje je bilo dovoljeno.
Vaša prijavna seja je potekla, zato ste bili odjavljeni. Prosimo, da se znova prijavite.