こんにちは、windows7 Ultimate マシンで mdf ファイル (sqlserver データベース ファイル) のバックアップを作成するための powershell スクリプトを作成しようとしています。
しかし、スクリプトを実行するとエラーが表示されます:
New-Object : Cannot find type [Microsoft.SqlServer.Management.Smo.Backup]: make sure the assembly
is loaded.
At C:\Users\abc\tmp.ps1:5 char:23
+ $dbBackup = new-object <<<< ("Microsoft.SqlServer.Management.Smo.Backup")
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
Property 'Database' cannot be found on this object; make sure it exists and is settable.
At C:\Users\abc\tmp.ps1:8 char:11
+ $dbBackup. <<<< Database = "ds"
+ CategoryInfo : InvalidOperation: (Database:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\abc\tmp.ps1:11 char:28
+ $dbBackup.Devices.AddDevice <<<< ("D:\backups\BLACKSWASTIK.bak", "File")
+ CategoryInfo : InvalidOperation: (AddDevice:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Property 'Action' cannot be found on this object; make sure it exists and is settable.
At C:\Users\abc\tmp.ps1:14 char:11
+ $dbBackup. <<<< Action="Database"
+ CategoryInfo : InvalidOperation: (Action:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\abc\tmp.ps1:17 char:20
+ $dbBackup.SqlBackup <<<< ($s)
+ CategoryInfo : InvalidOperation: (SqlBackup:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
ここに私のコードがあります:
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "localhost\sqlexpress2008"
$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
#Set the Database property to Northwind
$dbBackup.Database = "bs"
#Add the backup file to the Devices collection and specify File as the backup type
$dbBackup.Devices.AddDevice("D:\backups\BLACKSWASTIK.bak", "File")
#Specify the Action property to generate a FULL backup
$dbBackup.Action="Database"
#Call the SqlBackup method to generate the backup
$dbBackup.SqlBackup($s)
このコードは XP マシンでは正常に動作しますが、windows7 Ultimate マシンで実行したいのですが、何か変更が必要ですか? 提案してください....