Return Value from Get-NAVAppInfo powershell

jimmyf
Member Posts: 104
Is it possible to wrap Get-NAVAppInfo powershell command in a function to return certain values. For example the Synch state and the installation status?
Thanks you
Thanks you
0
Best Answer
-
So... Jimmy... Sorry for the ruckus in here, that kind of took over your question. I was actually trying to figure out how to make it work when Mr Nice Guy here started his 'process'. I'm not very good with PowerShell so it was a good way to see if I could make this work. My first instinct was to use Json. I found plenty of examples, but there was always a conversion to and from Json, and the real work is always done with this thing called a PSObject. I'm sure Json is easy enough once you figure out how that works in PowerShell, but as it turns out, using a PSObject is easier anyway, so here it goes...
You can load the output of a Cmdlet into a PSObject like this:$AppInfoRaw = Get-BCContainerAppInfo -containerName MyContainer -tenantSpecificProperties $true
To see the content of the object just select the object in your editor and hit F8. Try with and without the tenantSpecificProperties switch, that is what gets the sync state and installation status of the app.
From this point on, you can access the object members straight from the editor. All you have to do is load it once, and then intellisense will show you the members, even its sub-members:
Here's an example of how to read the app information from MyContainer into an object, loop through the object and display the content in a list:$AppInfoRaw = Get-BCContainerAppInfo -containerName MyContainer -tenantSpecificProperties $true $MyObjectList = @() foreach($AppInfo in $AppInfoRaw) { $obj = New-Object psobject -Property @{ ItsName = $AppInfo.Name ItsPublisher = $AppInfo.Publisher ItsInstalled = $AppInfo.IsInstalled ItsPublished = $AppInfo.IsPublished ItsSyncState = $AppInfo.SyncState } $MyObjectList += $obj } $MyObjectList | Format-Table
This gives the following output:
This is not all of it, because there are many more apps, but that's the content of the object
I'm going to write a blog post about this with more details, but I thought you'd be interested in seeing this right away. Let me know if this is what you were looking for5
Answers
-
Yes, I created powershel script once to get the content of the Version tag:
[xml]$xmlFile = Get-NAVAppInfo -Name 'MyApp' -ServerInstance 'BC140' | ConvertTo-Xml
$SelectedNode = [xml]$xmlFile | Select-XML -XPath "//Property[@Name='Version']" | Select-Object -ExpandProperty "node"
$TheVersion = $SelectedNode.InnerText0 -
You can also load a JSON object and access its members directly.
$MySettings = (Get-Content '.\PowerShell\MySettings.json') | ConvertFrom-Json $AppJSON = (Get-Content (Join-Path $MySettings.AppFolder '\app.json')) | ConvertFrom-Json
First this loads a JSON object that includes a member 'AppFolder', and in the second line I load app.json from my app folder. From there I can then access for instance the publisher by using $AppJSON.publisher.
Not sure if Get-NAVAppInfo loads the app information directly but you'd have to play around with it to make that happen0 -
@DenSter:
So please provide a working solution for Get-NAVAppInfo result processing this way.
I know how to convert a json file to powershell object, but using it this way
could make you end up with a complex type json.. that's what I remember encountering
trying to tackle this problem. So I choose the xml option as the best way to go.0 -
Not sure if Get-NAVAppInfo loads the app information directly but you'd have to play around with it to make that happen
0 -
No, got it all the first time.
Just hoped you could show us the playing around part. At least that would have contributed something.0 -
At least that would have contributed something.
I posted that for Jimmy, not you. I know you already know everything
0 -
Been trying to get it done in json, but this doesn't work. So I was hoping you'd shed some more light here to spare Jimmy my fate. Sincere disappointment.. still.0
-
You know, instead of insulting me, you might want to try asking in a friendly way next time, you get way more done that way. I put this together for Jimmy, because I think it may help him, instead of slogging through XML
You actually don't need a Json object. You can just read the output into a psobject and browse through them
0 -
I was asking nicely, you replied arrogantly.
As it was last time.
Good one! Spared Jimmy a lot of json hussle.0 -
At least that would have contributed something.
And you're welcome by the way, I know you meant to say thank you because you are such a nice guy
0 -
You're right. At that point I had stopped asking friendly. But hey screw the process, it's the results that count.0
-
The way people treat me is not what motivates me though, so your 'process' is not what got the results0
-
So... Jimmy... Sorry for the ruckus in here, that kind of took over your question. I was actually trying to figure out how to make it work when Mr Nice Guy here started his 'process'. I'm not very good with PowerShell so it was a good way to see if I could make this work. My first instinct was to use Json. I found plenty of examples, but there was always a conversion to and from Json, and the real work is always done with this thing called a PSObject. I'm sure Json is easy enough once you figure out how that works in PowerShell, but as it turns out, using a PSObject is easier anyway, so here it goes...
You can load the output of a Cmdlet into a PSObject like this:$AppInfoRaw = Get-BCContainerAppInfo -containerName MyContainer -tenantSpecificProperties $true
To see the content of the object just select the object in your editor and hit F8. Try with and without the tenantSpecificProperties switch, that is what gets the sync state and installation status of the app.
From this point on, you can access the object members straight from the editor. All you have to do is load it once, and then intellisense will show you the members, even its sub-members:
Here's an example of how to read the app information from MyContainer into an object, loop through the object and display the content in a list:$AppInfoRaw = Get-BCContainerAppInfo -containerName MyContainer -tenantSpecificProperties $true $MyObjectList = @() foreach($AppInfo in $AppInfoRaw) { $obj = New-Object psobject -Property @{ ItsName = $AppInfo.Name ItsPublisher = $AppInfo.Publisher ItsInstalled = $AppInfo.IsInstalled ItsPublished = $AppInfo.IsPublished ItsSyncState = $AppInfo.SyncState } $MyObjectList += $obj } $MyObjectList | Format-Table
This gives the following output:
This is not all of it, because there are many more apps, but that's the content of the object
I'm going to write a blog post about this with more details, but I thought you'd be interested in seeing this right away. Let me know if this is what you were looking for5
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions