locked
About SQL Provider RRS feed

  • Question

  • 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 PS 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:

    https://gist.github.com/anonymous/b60d8dae684546c1a0c4566fdc4627e4

    Thanks for your feedbacks on this!
    Cheers!

    Wednesday, October 12, 2016 12:25 PM

Answers

  • Workaround:

    pushd;Import-Module salps;popd

    It is only the load or autoloaded that does this.  After the module is loaded this will not happen


    \_(ツ)_/

    Wednesday, October 12, 2016 2:45 PM

All replies

  • Hi Teciluas,

    it appears that either importing the module or calling Invoke-Sqlcmd change your current location. Your best bet is to use Get-Location before calling it and store your current location into a variable. You can then use Set-Location to return to your position when your are done with Invoke-Sqlcmd.

    This is dirty behavior on the side of the SQL Module.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, October 12, 2016 1:51 PM
  • Workaround:

    pushd;Import-Module salps;popd

    It is only the load or autoloaded that does this.  After the module is loaded this will not happen


    \_(ツ)_/

    Wednesday, October 12, 2016 2:45 PM
  • Hi FWN,

    Thanks for your input.

    Yes, i taught so. I'll try the below solution see what's coming out of it...

    Thursday, October 13, 2016 9:42 AM
  • Hi jrv,

    Do i need to write this line before every call made for Invoke-Sqlcmd or just somewhere in the function body?

    Many Thanks !!!

    Thursday, October 13, 2016 9:43 AM