K
K
KJIayD2016-08-10 11:49:43
PowerShell
KJIayD, 2016-08-10 11:49:43

Error accessing sl "SQLSERVER:\". How to fix?

Good day.
When executing part of the script:

#Делаем бэкап всех баз в ранее созданую папку
sl "SQLSERVER:\sql\1cserver\sqlexpress\databases"
foreach($database in (Get-ChildItem)) {
 $dbName = $database.Name
 Backup-SqlDatabase -Database $dbName -BackupFile "c:\db\$current\$dbName.bak"
 }

gives an error message
sl : Не удалось найти диск. Диск с именем "SQLSERVER" не существует.
C:\script\Backup_MSSQL_day.ps1:11 знак:1
+ sl "SQLSERVER:\sql\1cserver\sqlexpress\databases"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (SQLSERVER:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
 
Backup-SqlDatabase : Не удалось разрешить путь "SQLSERVER:\" в объект типа "Microsoft.SqlServer.Management.Smo.Server". Поместите расположение в правильный контекст или воспользуйтесь параме
тром Path для указания расположения. 
C:\script\Backup_MSSQL_day.ps1:14 знак:2
+  Backup-SqlDatabase -Database $dbName -BackupFile "c:\db\$current\$dbName.bak"
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (SQLSERVER:\:String) [Backup-SqlDatabase], SqlPowerShellContextException
    + FullyQualifiedErrorId : ContextError,Microsoft.SqlServer.Management.PowerShell.BackupSqlDatabaseCommand

At the same time, if in Windows PowerShell ISE after the error is displayed, click "Run script" again, then the script runs without problems.
Question: Why does it work from the second launch? and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KJIayD, 2016-08-10
@KJIayD

Before
Inserted a line
Everything earned. Thanks to all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question