我有一个为 SQL Server 执行刷新过程的 SSIS 包。此过程需要在与运行包的凭据集不同的凭据集下执行某些查询。我创建了一组 PowerShell 脚本来处理必要的任务,RefreshMaster.ps1 调用 GrantPerms.ps1。
GrantPerms.ps1 使用 CredentialManager 模块 cmdlet Get-StoredCredential 来检索必要的凭据集,这是指定任务所必需的。该模块安装在 c:\Program Files\WindowsPowerShell\Modules 目录中,该目录包含在环境变量 PSModulePath 中。我使用以下命令为所有用户导入模块。
Import-Module CredentialManager
当我运行 Get-Module -ListAvailable 时,我看到模块列为 Binary,Ver 2.0。当我从 PowerShell 运行 RefreshMaster.ps1 时,一切正常,是的,我已经测试以确保正确的凭据被拾取并通过。但是,当我从 SSIS 调用 RefreshMaster.ps1 时,虽然是执行进程任务,但出现错误:
术语“Get-StoredCredential”未被识别为 cmdlet、函数、脚本、文件或可运行程序的名称。
示例代码:
#RefreshMaster.ps1
# Call GetCreds script
$ScriptBlock = [ScriptBlock]::Create("\\MyServer\MyShare\GetCreds.ps1")
Invoke-Command -ScriptBlock $ScriptBlock | Out-Null
#GetCreds.ps1
# retrieve credentials from Windows Credetial Manager
$storedCreds=Get-StoredCredential -Target 'MyCreds' -AsCredentialObject
我似乎无法弄清楚如何让它从 SSIS 正常运行。除了调用 Get-StoredCredentials 之外,所有其余代码似乎都运行良好。请帮忙!