Start a new topic
Answered

Powershell for Dynamic Folders Incorporating Properties

Hi,


I am using the powershell example on the support site to try to create Dynamic Folders for WebConnections.  I have no issue creating the base object from a CSV, but I'm getting stuck at adding other properties.  


From the examples for Dynamic Folders I've modified it to create a webconnection, but trying to add in other properties does not work.  For example in the code below, it imports and runs with no errors, but IgnoreCertificateErrors = True does not do anything.  Similar if using UseDedicatedEngine = True also does not check that check box.

     

$ErrorActionPreference = "Stop"
$computers = Import-Csv "$CustomProperty.CSVPath$"
$connections = @()

ForEach ($computer in $computers) {
    $name = $computer.Name
    $computerName = $computer.ComputerName
    $username = $computer.Username
    $password = $computer.Password

    $connection = New-Object pscustomobject -Property @{
        "Type" = "WEBConnection";
        "Name" = $name;
        "ComputerName" = "HTTPS://" + $computerName + "/xui";
        "IgnoreCertificateErrors" = "True";
    }
    $connections += $connection
}
@{
    Objects = $connections
} |
ConvertTo-Json -Depth 100 |
Write-Host

     If anyone has any ideas please let me know.


Many Thanks!


Best Answer

Hi,


please check out our updated docs here:

https://www.royalapplications.com/go/kb-all-royaljson


In the documentation PDF you can find a chapter:

Advanced scenarios


I hope this helps.


Regards,

Stefan


Sorry Figured out my own issue.  In order to add in "Properties" you need to include a properties HASH table.


So my code above looks like this:


 

$ErrorActionPreference = "Stop"

$computers = Import-Csv "$CustomProperty.CSVPath$"

$connections = @()

ForEach ($computer in $computers) {
    $name = $computer.Name
    $computerName = $computer.ComputerName

    $connection = New-Object pscustomobject -Property @{
        "Type" = "WebConnection";
        "Name" = $name;
        "ComputerName" = "HTTPS://" + $computerName;
		"CredentialName" = "BARRIE-ROOT";
		"Properties" = @{
		"UseDedicatedEngine" = "True"
		}
		
    }

    $connections += $connection
}

@{
    Objects = $connections
} |
ConvertTo-Json -Depth 100 |
Write-Host

 Note the "Properties" = @{} section in order to add in the extra properties.


Thanks

James

Answer

Hi,


please check out our updated docs here:

https://www.royalapplications.com/go/kb-all-royaljson


In the documentation PDF you can find a chapter:

Advanced scenarios


I hope this helps.


Regards,

Stefan

Login or Signup to post a comment