locked
Output pipe to a variable RRS feed

  • Question

  • I have been trying to work out to extract the output of the following command to a variable so that I can use it in another semi auto command.  This is what I mean:

    Get-RDRemoteApp -ConnectionBroker broker.contoso.com -Alias MyApp

    Output:

       

    CollectionName Alias      DisplayName   FilePath                            ShowIn CommandLin RequiredC   UserGroups             
                                                                                                     WebAcc eSetting       ommandLin                        
                                                                                                     ess                           e                                
    --------------     -----      -----------         --------                            ------    ----------      ---------       ----------             
    RemoteApps     MyApp   MyApp             \\unc\path\to\myApp.exe  True      DoNotAllow                    {contoso\grpUser}

    The I want to use the:

    $variable7 = "broker.contoso.com"

    Set-RDRemoteApp -Alias $variable1 -CollectionName $variable2 -DisplayName $variable3 -FolderName $variable4 -FilePath $variable5 -FileVirtualPath $variable4 -ConnectionBroker $variable7 -UserGroups @("$variable8")

    I hope it makes sense what I am trying to achieve and I hope its possible?

    Friday, December 29, 2017 3:59 PM

Answers

  • So, what it seems like you really want to do is get the value of "Get-RDRemoteApp" and use that data to create a new RDRemoteApp.

    What you need to do is this:

    $defaultData = Get-RDRemoteApp -ConnectionBroker broker.contoso.com -Alias MyApp

    Then you can use the data from this variable to populate the Set-RDRemoteApp or New-RDRemoteApp cmdlets:

    New-RDRemoteApp -Alias $alias -CollectionName $($defaultData.CollectionName) -DisplayName $displayName -FolderName $($defaultData.FolderName) -FilePath $filePath -FileVirtualPath $fileVirtualPath -ConnectionBroker $($defaultData.ConnectionBroker) -UserGroups $($defaultData.UserGroups)

    I left some of the variables alone, simply because you might not want to blindly copy data from one RDApp to another. But feel free to do so if that's what your business case requires.

    If you're wanting to set a specific setting on a RDRemoteApp, you can pipe the value of Get-RDRemoteApp to Set-RDRemoteApp and simply change what you want:

    Get-RDRemoteApp -ConnectionBroker broker.contoso.com -Alias MyApp | Set-RDRemoteApp -FilePath $newFilePath

    So, to sum up: 

    • All of your data from Get-RDRemoteApp is saved in the $defaultData variable.
    • Access the individual values by calling the variable and object (i.e. $defaultData.object).


    Jeremy Corbello | https://www.jeremycorbello.com


    • Edited by Jacorbello Friday, December 29, 2017 4:28 PM
    • Marked as answer by ChrisUKDE Friday, December 29, 2017 4:36 PM
    Friday, December 29, 2017 4:26 PM

All replies

  • No.  What is wrong with what you have?

    help about_variables

    Learn PowerShell  


    \_(ツ)_/

    Friday, December 29, 2017 4:24 PM
  • So, what it seems like you really want to do is get the value of "Get-RDRemoteApp" and use that data to create a new RDRemoteApp.

    What you need to do is this:

    $defaultData = Get-RDRemoteApp -ConnectionBroker broker.contoso.com -Alias MyApp

    Then you can use the data from this variable to populate the Set-RDRemoteApp or New-RDRemoteApp cmdlets:

    New-RDRemoteApp -Alias $alias -CollectionName $($defaultData.CollectionName) -DisplayName $displayName -FolderName $($defaultData.FolderName) -FilePath $filePath -FileVirtualPath $fileVirtualPath -ConnectionBroker $($defaultData.ConnectionBroker) -UserGroups $($defaultData.UserGroups)

    I left some of the variables alone, simply because you might not want to blindly copy data from one RDApp to another. But feel free to do so if that's what your business case requires.

    If you're wanting to set a specific setting on a RDRemoteApp, you can pipe the value of Get-RDRemoteApp to Set-RDRemoteApp and simply change what you want:

    Get-RDRemoteApp -ConnectionBroker broker.contoso.com -Alias MyApp | Set-RDRemoteApp -FilePath $newFilePath

    So, to sum up: 

    • All of your data from Get-RDRemoteApp is saved in the $defaultData variable.
    • Access the individual values by calling the variable and object (i.e. $defaultData.object).


    Jeremy Corbello | https://www.jeremycorbello.com


    • Edited by Jacorbello Friday, December 29, 2017 4:28 PM
    • Marked as answer by ChrisUKDE Friday, December 29, 2017 4:36 PM
    Friday, December 29, 2017 4:26 PM
  • Its a little project and I am trying to make a tool of my own so that I dont have to re-type all the parameters when issuing the command Set-RDRemoteApp, for example; if all I want to do is add more Usergroups to the Alias MyApp.

    so something like:

    $alias = Read-Host "Whats the Alias? "

    Get-RDRemoteApp -ConnectionBroker broker.contoso.com -Alias $alias

    Then the output I can pipe into variables to add UserGroups:

    $group = Read-Host "Type the name of the group you want to append? "

    Set-RDRemoteApp -Alias $alias etc etc etc etc -UserGroups @("$group")

    Friday, December 29, 2017 4:35 PM
  • Perfect, thank you jacorbello
    Friday, December 29, 2017 4:36 PM