Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing command output #12

Open
MacDogbert opened this issue Dec 27, 2016 · 2 comments
Open

Showing command output #12

MacDogbert opened this issue Dec 27, 2016 · 2 comments

Comments

@MacDogbert
Copy link

What do you think about modifying the functions to output the ItemDetails? When first starting with the module I found it very confusing that there was no useful output from a successful command. I've learned what to expect now and store all of the XML responses I get in variables, but it can be a bit tedious to have to store something in a variable if you just want to see the result quickly. I think this would also improve the learning curve for those starting out.

Example:
Get-ItemsByName command

Current behavior:

Get-ItemsByName -itemName ABCD -Server $server

xml                            ArrayOfItemDetails
---                            ------------------
version="1.0" encoding="utf-8" ArrayOfItemDetails

#Or when working with a variable:
$current=Get-ItemsByName -itemName ABCD -Server $server
$current.ArrayOfItemDetails.ItemDetails.Name
ABCD

Proposed behavior:

Get-ItemsByName2 -itemName ABCD -Server $server

Name               : ABCD
Guid               : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
TypeName           : ComputerResource
LongTypeName       : Altiris.Resource.StandardResources.ComputerResource
TypeGuid           : 539626d8-a35a-47eb-8b4a-64d3da110d01
ParentFolderName   : Computer
ParentFolderGuid   : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Attributes         : Normal
Enabled            : false
IsSchedulableItem  : false
ScheduleEnabled    : false
SharedScheduleGuid : 00000000-0000-0000-0000-000000000000

#Or when working with a variable:
$proposed=Get-ItemsByName2 -itemName ABCD -Server $server
$proposed.Name
ABCD

To get this result I modified the last few lines of the function to this:

    if($Credential)
    {
        $result=Invoke-RestMethod -Uri "https://$Server/$WebServiceUrl" -Method Post -Body $Body -Credential $Credential
    }
    else
    {
        $result=Invoke-RestMethod -Uri "https://$Server/$WebServiceUrl" -Method Post -Body $Body -UseDefaultCredentials
    }
$result.ArrayOfItemDetails.ItemDetails
}

The response from the server doesn't consistently use .ArrayOfItemDetails, this line would have to be customized for each function depending on what the server returns for each. This would be part of the benefit of this change, moving that work to the function instead of requiring the user determine the XML syntax each time.

Major downside is that any existing scripts would need to be modified as the return from the functions would change.

Let me know if you think this is worth doing, I'd be willing to help with this change.

Tiberriver256 added a commit that referenced this issue Dec 28, 2016
#12 modified ConvertTo-Function for better handling of xml responses.
@Tiberriver256
Copy link
Owner

Thanks for the input! I agree that is not quite intuitive.

I like how you laid out the code there. A pretty simple change but parsing everything to determine which functions need it might be a pain. How about we add something like this into the ConvertTo-Function script and kill the other common guid (#text) response too?

I'll push a commit in here with a quick sample and if it looks good we can re-run the autogeneratepsfunctions.ps1 and commit to have you test the module before pushing to the gallery

@MacDogbert
Copy link
Author

Yes that sounds good. I haven't looked at autogeneratepsfunctions.ps1, I'll have to take a look. I'm glad you have some ideas on how to script this.

I know just from some of the commands I've used there is a variety of XML keys that get returned that have the item details:
SoftwareCommandLineDetails.Guid
ItemDetails.Guid
SoftwarePackageDetails.guid
SoftwareComponentDetails.guid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants