SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Pass parameter into XML file using Powershell


Pass parameter into XML file using Powershell

Author
Message
Robin35
Robin35
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2997 Visits: 1290
Hi,

I have a project to automate SQL server restore.........use restore db's using third party tool called Simpana, Commvault.....we would like to automate the restore using powershell....i can restore the database using commnd prompt and powershell but to automate its pretty complicated.
We usually do restore in Simpana using its GUI...and Simpana has some commands for restore...and when using GUI we have an option to save the restore process as script...it saves as .xml file and .dat file....
To restore the database using powershell we need to use that xml file or we can create a dynamic xml file using that format..i was able to do that....
here is the dynamic xml file that i'm generating...i need to pass parameters in to this xml file e.g., db name, destination db name ,source server,dest server

Please let me know if anyone have any questions or need more information....

$template_Power = "<TMMsg_CreateTaskReq>

<taskInfo>
<task>
<taskFlags>
<disabled>false</disabled>
</taskFlags>
<policyType>DATA_PROTECTION</policyType>
<taskType>IMMEDIATE</taskType>
<initiatedFrom>COMMANDLINE</initiatedFrom>
<alert>
<alertName></alertName>
</alert>
</task>
<associations>
<backupsetName>defaultBackupSet</backupsetName>
<subclientName></subclientName>
<clientName></clientName>
<appName>SQL Server</appName>
<instanceName></instanceName>
</associations>
<subTasks>
<subTask>
<subTaskType>RESTORE</subTaskType>
<operationType>RESTORE</operationType>
</subTask>
<options>
<restoreOptions>
<browseOption>
<commCellId>2</commCellId>
<backupset>
<clientName></clientName>
<backupsetName>defaultBackupSet</backupsetName>
</backupset>
<timeRange/>
<noImage>true</noImage>
<useExactIndex>false</useExactIndex>
<mediaOption>
<library/>
<mediaAgent/>
<drivePool/>
<drive/>
<copyPrecedence>
<copyPrecedenceApplicable>false</copyPrecedenceApplicable>
<synchronousCopyPrecedence>0</synchronousCopyPrecedence>
<copyPrecedence>0</copyPrecedence>
</copyPrecedence>
<proxyForSnapClients>
<clientName></clientName>
</proxyForSnapClients>
</mediaOption>
<timeZone>
<TimeZoneName>(GMT-05:00) Eastern Time (US & Canada)</TimeZoneName>
</timeZone>
<listMedia>false</listMedia>
</browseOption>
<destination>
<destClient>
<clientName></clientName>
</destClient>
<destinationInstance>
<clientName></clientName>
<appName>SQL Server</appName>
<instanceName></instanceName>
</destinationInstance>
</destination>
<sqlServerRstOption>
<dbOnly>false</dbOnly>
<overWrite>true</overWrite>
<pointOfTimeRst>false</pointOfTimeRst>
<sqlRestoreType>DATABASE_RESTORE</sqlRestoreType>
<sqlRecoverType>STATE_RECOVER</sqlRecoverType>
<stopStartSSA>false</stopStartSSA>
<preserveReplicationSettings>false</preserveReplicationSettings>
<stopMarkRestore>false</stopMarkRestore>
<stopBeforeMarkRestore>false</stopBeforeMarkRestore>
<partialRestore>false</partialRestore>
<logShippingOnly>false</logShippingOnly>
<ffgRestore>false</ffgRestore>
<ignoreFullBackup>false</ignoreFullBackup>
<vSSBackup>false</vSSBackup>
<device>|DBA_Rep2|#12!DBA_Rep2_Test|#12!DBA_Rep|#12!D:\MSSQL\DATA\DBA_Rep2_Test.mdf|#12!D:\MSSQL\DATA\DBA_Rep2.mdf</device>
<device>|DBA_Rep2|#12!DBA_Rep2_Test|#12!DBA_Rep_log|#12!L:\MSSQL\LOG\DBA_Rep2_Test_log.ldf|#12!L:\MSSQL\LOG\DBA_Rep2_1.ldf</device>
<restoreSource>DBATest</restoreSource>
<database>DBATest</database>
<timeZone>
<TimeZoneName>(GMT-05:00) Eastern Time (US & Canada)</TimeZoneName>
</timeZone>
<keepDataCapture>false</keepDataCapture>
</sqlServerRstOption>
<fileOption>
<mapFiles/>
</fileOption>
<commonOptions>
<detectRegularExpression>true</detectRegularExpression>
<restoreDeviceFilesAsRegularFiles>false</restoreDeviceFilesAsRegularFiles>
<restoreSpaceRestrictions>false</restoreSpaceRestrictions>
<ignoreNamespaceRequirements>false</ignoreNamespaceRequirements>
<skipErrorsAndContinue>false</skipErrorsAndContinue>
<onePassRestore>false</onePassRestore>
<revert>false</revert>
<recoverAllProtectedMails>false</recoverAllProtectedMails>
<isFromBrowseBackup>false</isFromBrowseBackup>
<clusterDBBackedup>false</clusterDBBackedup>
</commonOptions>
</restoreOptions>
<adminOpts>
<updateOption/>
</adminOpts>
<commonOpts>
<startUpOpts>
<startInSuspendedState>false</startInSuspendedState>
<priority>66</priority>
<useDefaultPriority>true</useDefaultPriority>
</startUpOpts>
<prePostOpts>
<preRecoveryCommand></preRecoveryCommand>
<postRecoveryCommand></postRecoveryCommand>
<impersonation>
<!--PrePost Command Impersonation Level-->
<level>NO_SELECTION</level>
<user>
<userName></userName>
</user>
</impersonation>
<runPostWhenFail>false</runPostWhenFail>
</prePostOpts>
<!--User Description for the job-->
<jobDescription></jobDescription>
</commonOpts>
</options>
</subTasks>
</taskInfo>

</TMMsg_CreateTaskReq>"

$template_XML > C:\Program Files\Commvault\simpana\Base\template_restXML.xml
Nick_UK
Nick_UK
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1576 Visits: 1212
can you do a string replace on the areas you need to substitue in your parameters e.g

$Instance = "SQLInstance"

$template_Power = $template_Power.Replace("<instanceName></instanceName>","<instanceName>$Instance</instanceName>")


$template_Power > C:\Program Files\Commvault\simpana\Base\template_restXML.xml
Robin35
Robin35
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2997 Visits: 1290
Hey thanks for the response...i tried that its isnt working....can you please be more specific....
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search