Find Jobs
Hire Freelancers

Fix bug in powershell script executed from Sql server

€8-30 EUR

Törölve
Kiadva ekkor: több mint 7 évvel ezelőtt

€8-30 EUR

Teljesítéskor fizetve
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 -------------------------
Projektazonosító: 11656683

A projektről

7 ajánlat
Távolról teljesíthető projekt
Aktiválva: 8 évvel ezelőtt

Szeretne pénzt keresni?

A Freelancer oldalán történő árajánlatadás előnyei

Határozzon meg költségvetést és időkeretet
Kapja meg fizetését a munkáért
Vázolja ajánlatát
Ingyen regisztrálhat és adhat árajánlatot munkákra
7 szabadúszó adott átlagosan €51 EUR összegű árajánlatot erre a munkára
Felhasználó avatár
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 napon belül
5,0 (6 értékelés)
2,9
2,9
Felhasználó avatár
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 napon belül
0,0 (0 értékelés)
0,0
0,0
Felhasználó avatár
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 napon belül
0,0 (0 értékelés)
0,0
0,0

Az ügyfélről

NORWAY zászlója
Bjerkreim, Norway
4,8
5
Fizetési mód hitelesítve
Tagság kezdete: aug. 20, 2016

Ügyfél-hitelesítés

Köszönjük! E-mailben elküldtük a linket, melyen átveheti ajándék egyenlegét.
E-mailje elküldése során valami hiba történt. Kérjük, próbálja újra.
Regisztrált Felhasználók Összes Közzétett Munka
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Előnézet betöltése
Hozzáférést adott a helymeghatározáshoz.
Belépési munkamenete lejárt, és kijelentkeztettük. Kérjük, lépjen be újra.