Author Posts

October 12, 2016 at 12:20 pm

Hello,

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:

#Variable
$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!
Cheers!

October 12, 2016 at 1:52 pm

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

Thanks for you inputs!!
Cheers.

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

October 12, 2016 at 2:01 pm

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