0

阅读以下链接后,我能够解决我自己的问题 - 但有谁知道为什么在使用 invoke-sqlcmd 后需要文件系统提供程序,

即。为什么以下失败

$Doc_Folder = "\\Server.fqdn.com\c$\DocFiles" 
$DataSet = Invoke-Sqlcmd -Query $sqlQuery -ServerInstance $instanceName -username $SQLCreds.UserName -Password $pswd 
Get-ChildItem $Doc_Folder -recurse 

以及为什么以下工作

$Doc_Folder = "Microsoft.PowerShell.Core\FileSystem::\\Server.fqdn.com\c$\DocFiles" 
$DataSet = Invoke-Sqlcmd -Query $sqlQuery -ServerInstance $instanceName -username $SQLCreds.UserName -Password $pswd 
Get-ChildItem $Doc_Folder -recurse 

这是我找到添加文件系统提供程序Microsoft.PowerShell.Core\FileSystem:::
powershell-invoke-sqlcmd-get-childitem-cannot-call-method的解决方案的链接

4

1 回答 1

2

2016 年 8 月之前随 SQLServer 提供的 SQL Server 模块将目录更改为 SQLSERVER: 驱动器。

为了解决这个问题,您应该安装 SQLServer 模块(来自 PSGallery),或者,如果您需要使用旧的东西(出于兼容性原因),您可以这样做:

pushd
import-module SQLPS
popd

这将在导入模块后恢复当前目录。

于 2017-05-04T15:45:53.197 回答