阅读以下链接后,我能够解决自己的问题 - 但有人知道为什么在使用invoke-sqlcmd后需要FileSystem Provider 即。为什么以下失败
$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
答案 0 :(得分:2)
2016年8月之前SQLServer附带的SQL Server模块将目录更改为SQLSERVER:驱动器。
要解决这个问题,您应该安装SQLServer模块(来自PSGallery),或者,如果您需要使用较旧的东西(出于兼容性原因),您可以这样做:
pushd
import-module SQLPS
popd
这将在导入模块后恢复当前目录。