We’ve renamed the JSON Adapter Suggestions Supplier to PowerShell Adapter Suggestions Supplier! We
heard some good suggestions that the identify wasn’t as descriptive to what the suggestions supplier does so
we’ve modified it to be extra in step with its performance.
The Microsoft.PowerShell.PSAdapter is a module that identifies scripts and instruments on the consumer
machine that may assist customers extra convert native command output into PowerShell objects. We designed
this as a device that will help you uncover what instruments and scripts can be found that will help you convert native
output to PowerShell objects.
Be aware
Suggestions Suppliers are an experimental function of seven.4-preview3+ and so you’ll be required to make use of one of many 7.4 previews for JSON Adapters to work and have `PSFeedbackProvider` experimental function enabled .
Putting in PowerShell Adapter Suggestions Supplier
The discharge is out there from the PowerShell Gallery.
Use the next command to put in utilizing PowerShellGet v2.x:
Set up-Module -Title Microsoft.PowerShell.PSAdapter -AllowPrerelease
In case you are utilizing PSResourceGet, you need to use the next command:
Set up-PSResource -Title Microsoft.PowerShell.PSAdapter -AllowPrerelease
To make use of it it’s essential to import the module into your session:
Import-Module Microsoft.PowerShell.PSAdapter
We encourage you to incorporate this command in your $PROFILE
in order that it’s loaded in each PowerShell
session you begin.
What are PowerShell Adapters?
A PowerShell Adapter is a script that converts the textual content output of a local executable and converts
it to PowerShell objects. The PowerShell Adapter module is a suggestions supplier that identifies these
scripts and offers ideas while you run the native command with none adapter script. You may
learn extra about suggestions suppliers in our weblog publish, What are suggestions suppliers?.
You may make PowerShell Adapters for any command. Simply use the precise identify of the command because the
prefix to the script in order that the module can determine the script and recommend it. For instance, you
should identify the script <identify of command>-adapter.ps1
in order that the PowerShell Adapter can determine it
as a adapter script. This script’s file location should included in your $env:PATH
variable to be
discovered.
Creating an Adapter
For instance, you wish to use the macOS command vm_stat
like a PowerShell object. Create a file
known as vm_stat-adapter.ps1
and add the placement of this file to your $env:PATH
variable. The
PowerShell Adapter Suggestions Supplier will determine it as a attainable suggestion for vm_stat
.
Right here is an instance PowerShell Adapter for vm_stat
:
[CmdletBinding()]
param ( [Parameter(ValueFromPipeline=$true)][string]$inputObject )
BEGIN {
$h = @{}
}
PROCESS {
if ( $inputObject -match "^Mach Digital") {
if ($inputObject -match "web page measurement of (d+) ") {
$h['PageSize'] = [int]$matches[1]
}
}
else {
$okay,$v = $inputObject -split ":"
$AdjustedK = ($okay -replace "[ -]","_").trim() -replace '"'
$AdjustedV = "$v".Trim() -replace ".$"
$h[$AdjustedK] = [int64]$AdjustedV
}
}
END {
[pscustomobject]$h
}
The next reveals the suggestion from the Suggestions Supplier while you run vm_stat
with out the
adapter script:
For an additional instance, we will create a PowerShell Adapter for the df
utility utilizing the TextUtility
PowerShell module. We simply have to create a df-adapter.ps1
script and embody the next:
$enter | ConvertFrom-TextTable -ConvertPropertyValue
Help for jc
The JSON Converter, jc
, is a command line utility that converts textual content output to JSON for number of
command line instruments. The PowerShell Adapter module can recommend utilizing jc
as an adapter if the consumer
has it put in. Whenever you use a command supported by jc
, the PowerShell Adapter Suggestions Supplier
suggests utilizing jc
piped to ConvertFrom-JSON
.
You’ll find directions on easy methods to set up jc
and extra particulars concerning the device of their
supply code repository. When jc
helps the native command, this may be the best method
to transform the output without having to put in writing a PowerShell Adapter. You may see this suggestion in
the earlier screenshot for the df
instance.
jc
command helps many native instructions, nevertheless, the Suggestions Supplier solely offers jc
ideas for the next instructions:
"arp", "cksum", "crontab", "date", "df", "dig", "dir", "du", "file", "finger",
"free", "hash", "id", "ifconfig", "iostat", "jobs", "lsof", "mount", "mpstat",
"netstat", "route", "stat", "sysctl", "traceroute", "uname", "uptime", "w", "wc",
"who", "zipinfo"
Additionally, it’s worthwhile to use the suitable parameters together with your native command for jc
to work correctly.
For instance, if you wish to use jc
with uname
, it’s worthwhile to use uname -a
as a result of that produces
the output that jc
count on to transform to JSON.
Predictive IntelliSense Help
We’ve additionally added Predictive IntelliSense help for the PowerShell Adapter suggestions supplier. With
Predictive IntelliSense enabled, the PowerShell Adapter Suggestions Supplier offers ideas that
Predictive IntelliSense will present you on the command line. This makes it simple to strive instantly,
moderately than manually operating the suggestion.
Suggestions
We actually appreciated the suggestions we obtained on the primary announcement of this device and would like to
proceed getting nice suggestions! The GitHub repository for this device remains to be named
JSONAdapters, nevertheless the module identify is Microsoft.PowerShell.PSAdapter and any reference to
this device shall be PowerShell Adapters going ahead. You may submit any suggestions to the
JsonAdapter repository.
Thanks a lot!
Steven Bucher
PowerShell Workforce