About SQL Provider

This topic contains 2 replies, has 1 voice, and was last updated by  Tecina S. 1 year, 8 months ago.

  • Author
  • #55232

    Tecina S.


    I have a question about how providers work beyond the explanation of the extensive help file both online and in powershell help system.
    Each time, in my function when i invoke Invoke-Sqlcmd, if in the following lines the command are about file system provider, it fails because after the precedent command ran, it stays in SQLSERVER:\> provider prompt.
    The Workaround that i found, is to Set-Location to C:\> immediately after those commands. Is this a proper way of handling this? Is there a better way to do it? I tried and failed, using Push-Location and Pop-Location in the function not sure if i had a glimpse of cleverness. Please find below a few lines of the function:

    $bic= random ID
    $DRMaster = SRV1
    $DRSlave = SRV2
    $DRbicdir = folderonfirstserver
    $DRbicdir2 = folderonsecondserver
    #DB configuration
       Invoke-sqlcmd -InputFile "$DRbicdir2\__04_On_Primary_Set_DR_DB_srv1.sql" -ServerInstance "$DRSlave" -ErrorAction Stop
             Write-Host "trax_$bic is now set as the secondary log shipping FAILOVER database on $DRSlave" -ForegroundColor Green
    # Checking DB on $DRMaster is ONLINE in the DR solution.
    (Set-Location $DRbicdir)
    $testFODB = else { $false }

    Thanks for your feedbacks on this!

  • #55237

    Tecina S.

    Please excuse the quickness of my parsing code. Below is the entire version:

    Thanks for you inputs!!

    • This reply was modified 1 year, 8 months ago by  Tecina S.. Reason: Code formating
    • This reply was modified 1 year, 8 months ago by  Tecina S.. Reason: Code formatting
  • #55241

    Tecina S.

    Better have the gist url, as the formatting is messed up. here it's:
    Gist Code
    Sorry about that.

You must be logged in to reply to this topic.