Scripting for DeployR Server

Using the PowerShell Module to automate tasks or do lookups.

Authenicating to DeployR Server for Scripting

Depending on how you have configured security for your DeployR server, you might need to leverage the Connect-DeployR function to be able to authenticate before running commands. In my example, I'll be leveraging the passcode method of autentication.

Import-Module 'C:\Program Files\2Pint Software\DeployR\Client\PSModules\DeployR.Utility'
Connect-DeployR -Passcode PASSWORD

Once you've authenticated, you'll be able to retrieve information and content using PowerShell. One of the primary reasons for this would be to do backups of your items, for disaster recovery, or for importing into another DeployR instance, like prompting from test to prod.

You can create extensive backup scripts, filtering for specific items, or generic to backup everything. Getting data and exporting can be done with a couple of functions.

Exporting Content Items

Get-DeployRContentItem, when used without parameters, will pull back all content items, which you can then pipe into Export-DeployRContentItem

Get-DeployRContentItem | Export-DeployRContentItem -DestinationFolder "D:\Backups\Temp\"

Here is a sample code block where we filter out built in packages (-notlike '0000000-*'), and filter on purpose of "Other".

#Backup DeployR content items
Write-Host "Backing up DeployR content items..." -ForegroundColor Yellow
$ContentItems = Get-DeployRContentItem | Where-Object {$_.id -notlike '00000000-*'} | Where-Object {$_.contentItemPurpose -match "Other"} 
$ContentItems | ForEach-Object {
    write-host "Backing up content item: $($_.name) | $($_.id)" -ForegroundColor Cyan
    Export-DeployRContentItem -Id $_.id -DestinationFolder "D:\Backups\ContentItems\$($_.name)-$($_.id)"
}

Exporting Step Definitions

If you're creating step definitions for your organization, these too would be a great thing to backup. To get the step definition data, you'll use the Get-DeployRMetaData function with the -Type StepDefinition parameter. You can then Export that with the Export-DeployRStepDefinition function

Get-DeployRMetadata -Type StepDefinition

Here is a sample code block used to backup all Step definitions that aren't built in by default (-notlike '0000*')

#Backup DeployR step definitions
Write-Host "Backing up DeployR step definitions..." -ForegroundColor Yellow
$Steps = (Get-DeployRMetadata -Type StepDefinition | Where-Object {$_.id -notlike '0000*'})
$Steps | ForEach-Object {
    write-host "Backing up step definition: $($_.name) | $($_.id)" -ForegroundColor Cyan
    Export-DeployRStepDefinition -Id $_.id -DestinationFolder "D:\Backups\StepDefinitions\$($_.name)-$($_.id)"
}

Exporting Task Sequences

To export a task sequence, use Get-DeployRMetaData with the -Type TaskSequence parameter, then pipe that to Export-DeployRTaskSequence

Get-DeployRMetadata -Type TaskSequence

Here is a sample code block for exporting task sequences that are not built in

#Backup DeployR task sequences
Write-Host "Backing up DeployR task sequences..." -ForegroundColor Yellow
(Get-DeployRMetadata -Type TaskSequence | Where-Object {$_.id -notlike '0000*'}) | ForEach-Object {
    write-host "Backing up task sequence: $($_.name) | $($_.id)" -ForegroundColor Cyan
    Export-DeployRTaskSequence -Id $_.id -DestinationFolder "D:\Backups\TaskSequences\$($_.name)-$($_.id)"
}

Last updated