2016-04-06 41 views
-1

kullanarak SQL Server içerik veritabanının yedeğini alırken atılan hata PowerShell kullanarak SQL Server içerik veritabanının bir yedeğini almaya çalışıyorum. İşte PowerShell

benim kodudur:

$dt = Get-Date -Format yyyyMMddHHmmss 
$null = 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo"); 
    $srvrvinstancename= "srvr-04\mssqlserver1" 
    $svr = New-Object 
     Microsoft.SqlServer.Management.Smo.Server($srvrvinstancename); 
     #Write-Output $svr WSS_Content_2d426b353ded49aa8ace920d4178c298 
     $bdir = "C:" 
     $svnm = $svr.Name 
     $db = 
     $svr.Databases['WSS_Content_2d426b353ded49aa8ace920d4178c298'] 
     $dbname = $db.Name 
     $dt = get-date -format yyyyMMddHHmmss 
     $bfil = "$bdir\$($dbname)_db_$($dt).bak" 
     Backup-SqlDatabase -ServerInstance $svnm -Database $dbname - 
     BackupFile $bfil 

ama kodu çalıştırdığınızda hata iletisi: Ondan sonra,

import-module sqlps 

ran

Backup-SqlDatabase : The 'Backup-SqlDatabase' command was found in the module 'SQLPS', but the module could not be loaded. For more information, run 'Import-Module SQLPS'.
At line:19 char:1
+ Backup-SqlDatabase -ServerInstance $svnm -Database $dbname -BackupFile $bfil + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Backup-SqlDatabase:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Ama bu da bitti hata durumuna dön:

Import-Module : File C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS\Sqlps.ps1 cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170 .
At line:1 char:1
+ Import-Module SQLPS
+ ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [Import-Module], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand

Neyi yanlış yapıyorum?

+0

anlamadı (PowerShell yönetici olarak) yapmanız gereken yürütülemez komut dosyaları için

. – SaMolPP

+0

Birisi muhtemelen kod formatınızı beğenmedi. –

cevap

1

Sana Meclis kapalı bir çift yüklemeniz gerekir düşünüyorum:

# Load SQL server assemblies 
# 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")   | Out-Null 

# SmoExtended 
# 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")  | Out-Null 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")   | Out-Null 

GÜNCELLEME. Benim soru aşağı neden seçildi

Set-ExecutionPolicy remotesigned 
+0

Denedim, ancak aynı hatayı alıyorum. sql server 2012 SP1 Ent .Edition – SaMolPP

+0

kullanıyorum test ediyorum şimdi ... – SaMolPP

+0

sqlps modülü – Jeffrey