Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

***-PSSnapin SQLServerCmdLetSnapin110 ....cannot add

$
0
0
HelloI have gotten part of this powershell script from the web, and first part configured by me.#Define Variables and configure variables#----------------------------------------#First Set the target database on server1$targetdb ="DevTest2010_Content80_Portal_ProjServSitCol"#Now set the source database from server2$sourcedb="Prod2010_Content80_Portal_ProjServSitCol"#Define the main source of backup folder$Mainsource = "\\server3\location1\"#concatenate Main Source and Source DAtabase name to get the full path to the file containing the backup you wish to use for restore.$FullSource=$MainSource+$sourcedbwrite-host $fullsource#find the name of the file$backupfilename = get-childitem $FullSource -Exclude *.trn | sort-object -descending lastwritetime |select Name -first 1write-host $backupfilename.name#Concatenate the $fullsrouce with the FileName to feed to the restore command$sourcefilename=$fullsource+"\"+$backupfilename.namewrite-host $sourcefilename[ScriptBlock] $global:RestoreDB = { param ([string] $targetdb, [string] $FullSource, [string] $sqlDataPath, [string] $dataLogicalName, [string] $logLogicalName) [string] $dbCommand = "RESTORE DATABASE [$targetdb] " + "FROM DISK = N'$FullSource' " + "WITH FILE = 1, " + "MOVE N'$dataLogicalName' " + "TO N'$sqlDataPath\$targetdb.mdf', " + "MOVE N'$logLogicalName' " + "TO N'$sqlDataPath\$targetdb.ldf', " + "NOUNLOAD, STATS = 10" $sqlSnapin = Get-PSSnapin | where {$_.Name -eq "SqlServerCmdletSnapin110"} if($sqlSnapin -eq $null) { Add-PSSnapin SqlServerCmdletSnapin110 } Invoke-Sqlcmd -Query $dbCommand}It does not let me run Add-PSSnapin SqlServerCmdletSnapin110. Error message I get is, "Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2."I could not find anything on the web that would help me overcome this.

Viewing all articles
Browse latest Browse all 467

Trending Articles