Find Jobs
Hire Freelancers

Fix bug in powershell script executed from Sql server

€8-30 EUR

Peruutettu
Julkaistu yli 7 vuotta sitten

€8-30 EUR

Maksettu toimituksen yhteydessä
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 -------------------------
Projektin tunnus (ID): 11656683

Tietoa projektista

7 ehdotukset
Etäprojekti
Aktiivinen 8 vuotta sitten

Haluatko ansaita rahaa?

Freelancerin tarjouskilpailun edut

Aseta budjettisi ja aikataulu
Saa maksu työstäsi
Kuvaile ehdotustasi
Rekisteröinti ja töihin tarjoaminen on ilmaista
7 freelancerit tarjoavat keskimäärin €51 EUR tätä projektia
Käyttäjän avatar
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 1 päivässä
5,0 (6 arvostelua)
2,9
2,9
Käyttäjän avatar
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 1 päivässä
0,0 (0 arvostelua)
0,0
0,0
Käyttäjän avatar
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 1 päivässä
0,0 (0 arvostelua)
0,0
0,0

Tietoja asiakkaasta

Maan NORWAY lippu
Bjerkreim, Norway
4,8
5
Maksutapa vahvistettu
Liittynyt elok. 20, 2016

Asiakkaan vahvistus

Kiitos! Olemme lähettäneet sinulle sähköpostitse linkin, jolla voit lunastaa ilmaisen krediittisi.
Jotain meni pieleen lähetettäessä sähköpostiasi. Yritä uudelleen.
Rekisteröitynyttä käyttäjää Ilmoitettua työtä yhteensä
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Ladataan esikatselua
Lupa myönnetty Geolocation.
Kirjautumisistuntosi on vanhentunut ja sinut on kirjattu ulos. Kirjaudu uudelleen sisään.