SQL Server 2012 SQLPs Module - Changing current location automatically?

前端 未结 3 2168
天涯浪人
天涯浪人 2021-02-19 04:56

I have a large library of existing powershell scripts, primarily to run some complicated logic and interactions between SQL Server and the file system.

The SQL interac

相关标签:
3条回答
  • 2021-02-19 05:22

    A little more information on WHY in sql 2012 it is changing to the SQLSERVER: directory...

    When powershell imports sqlps module, the manifest defines a post script file named SqlPsPostScript.ps1. This file (first line) changes the current location to the SQLSERVER: provider

    On x64 bit box the module is located - C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS.

    In powershell 3.0 automatic importing can make it difficult to tell when this will occur (in my experience).

    Its not clear why (from a logical standpoint) it should do this. We don't want to touch the SQL server modules, so I guess you need to do an explicit set-location after import of the module. You might also look at this as a solution that's a little less hacky.

    Push-Location
    Import-Module sqlps
    Pop-Location
    
    0 讨论(0)
  • 2021-02-19 05:30

    I've solved this problem by adding a cd <local folder> as the first line of the script to break out of the provider. Feels hackish though.

    0 讨论(0)
  • 2021-02-19 05:42

    I solved a similar problem by using the PSPath property (which contain Microsoft.PowerShell.Core\FileSystem::) of the file I was trying to copy, instead of the default property. Hope it helps !

    0 讨论(0)
提交回复
热议问题