SQL Server 2012 SQLPs 模块 - 自动更改当前位置? [英] SQL Server 2012 SQLPs Module - Changing current location automatically?

查看:34
本文介绍了SQL Server 2012 SQLPs 模块 - 自动更改当前位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型的现有 powershell 脚本库,主要用于在 SQL Server 和文件系统之间运行一些复杂的逻辑和交互.

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

SQL 交互通常通过 cmdlet Invoke-SQLCmd 执行.

The SQL interactions typically are performed through the cmdlet Invoke-SQLCmd.

最近我所有服务器上的 SSMS 版本都升级到 2012.这意味着我必须对我的代码进行一些更改以删除对 sqlserverprovidersnapin100sqlservercmdletsnapin100 的引用因为这些在 2012 年已被弃用,以支持导入 SQLPs 模块.

Recently the SSMS version on all of my servers was upgraded to 2012. This meant I had to make some changes to my code to remove references to the sqlserverprovidersnapin100 and sqlservercmdletsnapin100 since those are deprecated in 2012 in favor of importing the SQLPs module.

这工作正常,但似乎 SQLPs 模块在某个时候将当前位置更改为 PS SQLSERVER> 而不是 ;,这让我的很多其他命令都失败了.例如,如果我在网络驱动器上运行 Test-Path,它可以从 位置正常工作,但会从 SQLSERVER 位置.

This has worked OK, but it seems that the SQLPs module is at some point changing the current location to PS SQLSERVER> instead of <local folder>, which makes a lot of my other commands fail. For instance, if I run a Test-Path on a network drive, it works fine from the <local folder> location but will fail from the SQLSERVER location.

这是一个已知问题吗?有没有我可以为此更改的解决方法或设置?

我担心的主要脚本超过 1000 行,并且在我们进行此更改之前已经运行了两年多没有问题,因此如果可以,我想避免对其进行逐行测试.

The main script I am worried about is over 1000 lines and has run with no issues for over two years until we made this change, so I'd like to avoid doing a line by line test of it if I can.

推荐答案

我通过添加一个 cd 作为脚本的第一行来解决这个问题提供者.虽然感觉很hackish.

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.

这篇关于SQL Server 2012 SQLPs 模块 - 自动更改当前位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆