Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:28+00:00 2026-05-23T03:57:28+00:00

I have a function to restore sql server database using Microsoft.SqlServer.Management.Smo.Restore. There is an

  • 0

I have a function to restore sql server database using “Microsoft.SqlServer.Management.Smo.Restore. There is an event called completed and within the code I put

 Register-ObjectEvent -InputObject $restore  -EventName "Complete" -SourceIdentifier CompleteRestore -Action { Write-Host "Works"} | Out-Null

It works perfectly and the message appears when the restore finishes.

When I run the function by Powershell Job, The restore is done,but the message does not appear.

Can You Help me guys ?

Thanks

I am using this code to run the function as a job and the Register-Object is inside the Invoke-SqlRestoreEventing Function

$server = "."
$dbname = "TestPoshEventing_6"
$filepath = "c:\temp\backup\TestPoshEventing.bak"
$Realocatefiles = @{TestPoshEventing='c:\temp\restore\TestPoshEventing_6.mdf';TestPoshEventing_log='c:\temp\restore\TestPoshEventing_6.ldf'}
Start-Job -Name "Restore1" -InitializationScript  {Import-Module c:\temp\testes\PoshTest.psm1 -Force} -scriptblock { Invoke-SqlRestoreEventing -sqlserver $args[0] -dbname $args[1]  -filepath $args[2] -relocatefiles $args[3] -force } -ArgumentList $server, $Dbname ,$filepath ,$Realocatefiles
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:57:29+00:00Added an answer on May 23, 2026 at 3:57 am

    Background jobs run in a different runspace. So, anything you output there won’t appear at the console. You can modify your code to do that. Check this for example,

    $server = "."
    $dbname = "TestPoshEventing_6"
    $filepath = "c:\temp\backup\TestPoshEventing.bak"
    $Realocatefiles = @{TestPoshEventing='c:\temp\restore\TestPoshEventing_6.mdf';TestPoshEventing_log='c:\temp\restore\TestPoshEventing_6.ldf'}
    $job = Start-Job -Name "Restore1" -InitializationScript  {Import-Module c:\temp\testes\PoshTest.psm1 -Force} -scriptblock { Invoke-SqlRestoreEventing -sqlserver $args[0] -dbname $args[1]  -filepath $args[2] -relocatefiles $args[3] -force } -ArgumentList $server, $Dbname ,$filepath ,$Realocatefiles
    
    Wait-Job $job | Receive-Job
    

    By using Receieve-Job when the background job completes, you can see the output of your register-ObjectEvent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have .net app in which there is function for Database backup and restore.
I have a function, parseQuery, that parses a SQL query into an abstract representation
I have a function pointer defined by: typedef void (*EventFunction)(int nEvent); Is there a
I have a function that I use called sqlf(), it emulates prepared statements. For
I'm working with an SQL Server database with about 50 tables and plenty of
I have a function which prosecces first N files in the direcory: def restore(cnt)
I want to make a database restore function that will parse a dump made
I am trying to have the function vbsme call another function called sad... is
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.