Skip to content

Instantly share code, notes, and snippets.

@jimmcslim
Created September 22, 2015 06:30
Show Gist options
  • Save jimmcslim/35fe64d203a74506a9f0 to your computer and use it in GitHub Desktop.
Save jimmcslim/35fe64d203a74506a9f0 to your computer and use it in GitHub Desktop.
A collection of Powershell functions that make the RoyalTS Powershell module a little more sane to work with.
function Load-RoyalDocument
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)] [string] $Path
)
$cred = Get-Credential
$store = New-RoyalStore -UserName $cred.UserName
$document = Open-RoyalDocument -Store $store -FileName $path -Password $cred.Password
return $store
}
function Get-RoyalObjectAtPath
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)] $Store,
[Parameter(Mandatory=$true)] [string] $Path,
[Parameter(Mandatory=$true)] [string] $Type
)
$segments = $Path.Split('\')
for ($i = 0; $i -lt ($segments.Length - 1); $i++) {
if ($folder -eq $null) {
$folder = Get-RoyalObject -Store $Store -Name $segments[$i] -Type RoyalFolder
} else {
$folder = Get-RoyalObject -Folder $folder -Name $segments[$i] -Type RoyalFolder
}
}
$object = Get-RoyalObject -Folder $folder -Name $segments[$segments.Length - 1] -Type $Type
return $object
}
function Get-RoyalCredential
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)] $RoyalObject
)
$credentialId = $RoyalObject.CredentialId
if ($credentialId -eq [System.Guid]::Empty) {
$username = $RoyalObject.CredentialUsername
$password = $RoyalObject.CredentialPassword
} else {
$credentialObject = Get-RoyalObject -Store $RoyalObject.Store -Id $credentialId
$username = $credentialObject.UserName
$password = $credentialObject.Password
}
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -AsPlainText $password -Force)
return $cred
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment