SQL Server PowerShell错误Get-ChildItem

时间:2018-01-04 09:32:35

标签: sql-server powershell get-childitem

我尝试使用此PowerShell代码从SQL数据库获取备份:

Set-Location "SQLSERVER:\SQL\computer\distance\Databases"
foreach ($database in (Get-ChildItem)) {
    $dbName = $database.Name
    Backup-SqlDatabase -Database $dbName -BackupFile "E:\bu\$dbName"
}

在虚拟服务器中它可以工作。 当我转到SQLSERVER:\ SQL \ computer \ distance \ Databases位置并取ls 它显示我的数据库并成功进行备份。

但在我工作场所的另一台服务器中,它出现了这个错误:

Get-ChildItem : SQL Server PowerShell provider error: Failed to read child items.
[Failed to connect to server computer\instance. --> Login failed for user
'work\sql'.]
At line:1 char:23
+ ForEach($database in (Get-ChildItem))
+                       ~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (SQLSERVER:\SQL\...\instance\Databases:SqlPath) [Get-ChildItem], GenericProviderException
    + FullyQualifiedErrorId : CannotReadChildItems,Microsoft.PowerShell.Commands.GetChildItemCommand

在SQLSERVER:\ SQL \ computer \ distance \ Databases目录下我做ls时出现此错误:

ls : SQL Server PowerShell provider error: Failed to read child items. [Failed to
connect to server computer\instance. --> Login failed for user 'work\sql'.]
At line:1 char:1
+ ls
+ ~~
    + CategoryInfo          : ReadError: (SQLSERVER:\SQL\...\instance\Databases:SqlPath) [Get-ChildItem], GenericProviderException
    + FullyQualifiedErrorId : CannotReadChildItems,Microsoft.PowerShell.Commands.GetChildItemCommand

computer \ instance:我改变了这个例子。

0 个答案:

没有答案