{"id":20099,"date":"2023-08-28T14:42:15","date_gmt":"2023-08-28T22:42:15","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/powershell\/?p=20099"},"modified":"2023-08-28T14:42:15","modified_gmt":"2023-08-28T22:42:15","slug":"powershell-adapter-feedback-provider","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/powershell-adapter-feedback-provider\/","title":{"rendered":"PowerShell Adapter Feedback Provider"},"content":{"rendered":"<h2>PowerShell Adapter Feedback Provider<\/h2>\n<p>We&#8217;ve renamed the <a href=\"https:\/\/devblogs.microsoft.com\/powershell\/json-adapter-feedback-provider\/\">JSON Adapter Feedback Provider<\/a> to PowerShell Adapter Feedback Provider! We\nheard some good feedback that the name wasn&#8217;t as descriptive to what the feedback provider does so\nwe&#8217;ve changed it to be more consistent with its functionality.<\/p>\n<p>The <strong>Microsoft.PowerShell.PSAdapter<\/strong> is a module that identifies scripts and tools on the user\nmachine that can help users more convert native command output into PowerShell objects. We designed\nthis as a tool to help you discover what tools and scripts are available to help you convert native\noutput to PowerShell objects.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Note<\/strong><\/p>Feedback Providers are an experimental feature of 7.4-preview3+ and so you will be required to use one of the 7.4 previews for JSON Adapters to work and have `PSFeedbackProvider` experimental feature enabled .<\/div><\/p>\n<h2>Installing PowerShell Adapter Feedback Provider<\/h2>\n<p>The release is available from the <a href=\"https:\/\/www.powershellgallery.com\/packages\/Microsoft.PowerShell.PSAdapter\/0.3.0\">PowerShell Gallery<\/a>.<\/p>\n<p>Use the following command to install using <strong>PowerShellGet<\/strong> v2.x:<\/p>\n<pre><code class=\"language-powershell\">Install-Module -Name Microsoft.PowerShell.PSAdapter -AllowPrerelease<\/code><\/pre>\n<p>If you are using <strong>PSResourceGet<\/strong>, you can use the following command:<\/p>\n<pre><code class=\"language-powershell\">Install-PSResource -Name Microsoft.PowerShell.PSAdapter -AllowPrerelease<\/code><\/pre>\n<p>To use it you must import the module into your session:<\/p>\n<pre><code class=\"language-powershell\">Import-Module Microsoft.PowerShell.PSAdapter<\/code><\/pre>\n<p>We encourage you to include this command in your <code>$PROFILE<\/code> so that it&#8217;s loaded in every PowerShell\nsession you start.<\/p>\n<h2>What are PowerShell Adapters?<\/h2>\n<p>A PowerShell Adapter is a script that converts the text output of a native executable and converts\nit to PowerShell objects. The PowerShell Adapter module is a feedback provider that identifies these\nscripts and provides suggestions when you run the native command without any adapter script. You can\nread more about feedback providers in our blog post, <a href=\"https:\/\/devblogs.microsoft.com\/powershell\/what-are-feedback-providers\/\">What are feedback providers?<\/a>.<\/p>\n<p>You can make PowerShell Adapters for any command. Just use the exact name of the command as the\nprefix to the script so that the module can identify the script and suggest it. For example, you\nmust name the script <code>&lt;name of command&gt;-adapter.ps1<\/code> so that the PowerShell Adapter can identify it\nas a adapter script. This script&#8217;s file location must included in your <code>$env:PATH<\/code> variable to be\nfound.<\/p>\n<h2>Creating an Adapter<\/h2>\n<p>For example, you want to use the macOS command <code>vm_stat<\/code> like a PowerShell object. Create a file\ncalled <code>vm_stat-adapter.ps1<\/code> and add the location of this file to your <code>$env:PATH<\/code> variable. The\nPowerShell Adapter Feedback Provider will identify it as a possible suggestion for <code>vm_stat<\/code>.<\/p>\n<p>Here is an example PowerShell Adapter for <code>vm_stat<\/code>:<\/p>\n<pre><code class=\"language-powershell\">[CmdletBinding()]\r\nparam ( [Parameter(ValueFromPipeline=$true)][string]$inputObject )\r\nBEGIN {\r\n    $h = @{}\r\n}\r\n\r\nPROCESS {\r\n    if ( $inputObject -match \"^Mach Virtual\") {\r\n        if ($inputObject -match \"page size of (\\d+) \") {\r\n            $h['PageSize'] = [int]$matches[1]\r\n        }\r\n    }\r\n    else {\r\n        $k,$v = $inputObject -split \":\"\r\n        $AdjustedK = ($k -replace \"[ -]\",\"_\").trim() -replace '\"'\r\n        $AdjustedV = \"$v\".Trim() -replace \"\\.$\"\r\n        $h[$AdjustedK] = [int64]$AdjustedV\r\n    }\r\n}\r\n\r\nEND {\r\n    [pscustomobject]$h\r\n}<\/code><\/pre>\n<p>The following shows the suggestion from the Feedback Provider when you run <code>vm_stat<\/code> without the\nadapter script:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2023\/08\/vm_stat.png\" alt=\"Screenshot showing vm_stat suggestions.\" \/><\/p>\n<p>For another example, we can create a PowerShell Adapter for the <code>df<\/code> utility using the <code>TextUtility<\/code>\nPowerShell module. We just need to create a <code>df-adapter.ps1<\/code> script and include the following:<\/p>\n<pre><code class=\"language-powershell\">$input | ConvertFrom-TextTable -ConvertPropertyValue<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2023\/08\/dfadapter.png\" alt=\"DF utility adapter\" \/><\/p>\n<h2>Support for <code>jc<\/code><\/h2>\n<p>The JSON Converter, <code>jc<\/code>, is a command line utility that converts text output to JSON for variety of\ncommand line tools. The PowerShell Adapter module can suggest using <code>jc<\/code> as an adapter if the user\nhas it installed. When you use a command supported by <code>jc<\/code>, the PowerShell Adapter Feedback Provider\nsuggests using <code>jc<\/code> piped to <code>ConvertFrom-JSON<\/code>.<\/p>\n<p>You can find instructions on how to install <code>jc<\/code> and more details about the tool in their\n<a href=\"https:\/\/github.com\/kellyjonbrazil\/jc\">source code repository<\/a>. When <code>jc<\/code> supports the native command, this can be the simplest way\nto convert the output without needing to write a PowerShell Adapter. You can see this suggestion in\nthe previous screenshot for the <code>df<\/code> example.<\/p>\n<p><div class=\"alert alert-info\">\nThe <code>jc<\/code> command supports many native commands, however, the Feedback Provider only provides <code>jc<\/code>\nsuggestions for the following commands:<\/p>\n<pre><code>\"arp\", \"cksum\", \"crontab\", \"date\", \"df\", \"dig\", \"dir\", \"du\", \"file\", \"finger\",\r\n\"free\", \"hash\", \"id\", \"ifconfig\", \"iostat\", \"jobs\", \"lsof\", \"mount\", \"mpstat\",\r\n\"netstat\", \"route\", \"stat\", \"sysctl\", \"traceroute\", \"uname\", \"uptime\", \"w\", \"wc\",\r\n\"who\", \"zipinfo\"<\/code><\/pre>\n<p>Also, you need to use the appropriate parameters with your native command for <code>jc<\/code> to work properly.\nFor example, if you want to use <code>jc<\/code> with <code>uname<\/code>, you need to use <code>uname -a<\/code> because that produces\nthe output that <code>jc<\/code> expect to convert to JSON.\n<\/div><\/p>\n<h2>Predictive IntelliSense Support<\/h2>\n<p>We&#8217;ve also added Predictive IntelliSense support for the PowerShell Adapter feedback provider. With\nPredictive IntelliSense enabled, the PowerShell Adapter Feedback Provider provides suggestions that\nPredictive IntelliSense will show you on the command line. This makes it easy to try immediately,\nrather than manually running the suggestion.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2023\/08\/predictiveintellisense.png\" alt=\"Screenshot showing predictive intellisense support\" \/><\/p>\n<h2>Feedback<\/h2>\n<p>We really appreciated the feedback we got on the first announcement of this tool and would love to\ncontinue getting great feedback! The GitHub repository for this tool is still named\n<strong>JSONAdapters<\/strong>, however the module name is <strong>Microsoft.PowerShell.PSAdapter<\/strong> and any reference to\nthis tool will be <strong>PowerShell Adapters<\/strong> going forward. You can submit any feedback to the\n<a href=\"https:\/\/github.com\/PowerShell\/JsonAdapter\">JsonAdapter repository<\/a>.<\/p>\n<p>Thank you so much!<\/p>\n<p>Steven Bucher<\/p>\n<p>PowerShell Team<\/p>\n<p><!-- Link references --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog outlines the PowerShell Adapter Feedback Provider module<\/p>\n","protected":false},"author":98569,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3189,3190],"class_list":["post-20099","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-feedback-providers","tag-powershell-adapters"],"acf":[],"blog_post_summary":"<p>This blog outlines the PowerShell Adapter Feedback Provider module<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/20099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/98569"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=20099"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/20099\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=20099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=20099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=20099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}