Muokkaa

Jaa


ConvertTo-JsonForPSWS

Converts an object to a JSON-formatted string for PowerShell Web Services.

Syntax

ConvertTo-JsonForPSWS
              [-InputObject] <Object>
              [-Depth <Int>]
              [-Compress]
              [<CommonParameters>]

Description

The ConvertTo-JsonForPSWS cmdlet converts any object to a string in JavaScript Object Notation (JSON) format for PowerShell Web Services. The properties are converted to field names, the property values are converted to field values, and the methods are removed.

You can then use the ConvertTo-JsonForPSWS cmdlet to convert a JSON-formatted string to a JSON object, which is easily managed in Windows PowerShell.

Examples

-------------------------- Example 1 --------------------------

PS C:\> (Get-UICulture).Calendar | ConvertTo-JsonForPSWS
{
    "MinSupportedDateTime":  "\/Date(-62135568000000)\/",
    "MaxSupportedDateTime":  "\/Date(253402300799999)\/",
    "AlgorithmType":  "SolarCalendar",
    "CalendarType":  "Localized",
    "Eras":  [
                 1
             ],
    "TwoDigitYearMax":  2029,
    "IsReadOnly":  false
}

This command uses the ConvertTo-JsonForPSWS cmdlet to convert a GregorianCalendar object to a JSON-formatted string for PowerShell Web Services.

-------------------------- Example 2 --------------------------

PS C:\> @{Account="User01";Domain="Domain01";Admin="True"} | ConvertTo-JsonForPSWS -Compress
{"Admin":"True","Account":"User01","Domain":"Domain01"}

This command shows the effect of using the Compress parameter of ConvertTo-JsonForPSWS. The compression affects only the appearance of the string, not its validity.

-------------------------- Example 3 --------------------------

PS C:\> Get-Date | Select-Object -Property * | ConvertTo-JsonForPSWS
{
    "DisplayHint":  {
                        "value":  2,
                        "Value":  "DateTime"
                    },
    "DateTime":  "domingo, 27 de mayo de 2018 19:01:15",
    "Date":  "\/Date(1527390000000)\/",
    "Day":  27,
    "DayOfWeek":  {
                      "value":  0,
                      "Value":  "Sunday"
                  },
    "DayOfYear":  147,
    "Hour":  19,
    "Kind":  {
                 "value":  2,
                 "Value":  "Local"
             },
    "Millisecond":  225,
    "Minute":  1,
    "Month":  5,
    "Second":  15,
    "Ticks":  636630444752251610,
    "TimeOfDay":  {
                      "Hours":  19,
                      "Minutes":  1,
                      "Seconds":  15,
                      "Ticks":  684752251610,
                      "Days":  0,
                      "Milliseconds":  225,
                      "TotalDays":  0.79253732825231482,
                      "TotalHours":  19.020895878055555,
                      "TotalMilliseconds":  68475225.161,
                      "TotalMinutes":  1141.2537526833335,
                      "TotalSeconds":  68475.225161
                  },
    "Year":  2018
}

This command shows how to use the ConvertTo-JsonForPSWS cmdlet to convert an object to a JSON string for PowerShell Web Services.

It uses the ConvertTo-JsonForPSWS cmdlet to convert a System.DateTime object from the Get-Date cmdlet to a JSON-formatted string for PowerShell Web Services. The command uses the Select-Object cmdlet to get all () of the properties of the *DateTime object. The output shows the JSON string that ConvertTo-JsonForPSWS returned.

-------------------------- Example 4 --------------------------

PS C:\> $JsonSecurityHelp = Get-Content $Pshome\Modules\Microsoft.PowerShell.Security\en-US\Microsoft.PowerShell.Security.dll-Help.xml | ConvertTo-JsonForPSWS

This command uses the ConvertTo-JsonForPSWS cmdlet to convert a Windows PowerShell Help file from XML format to JSON format for PowerShell Web Services.

Parameters

-Compress

Omits white space and indented formatting in the output string.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Skype for Business Online

-Depth

Specifies how many levels of contained objects are included in the JSON representation. The default value is 2.

Type:Int
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Skype for Business Online

-InputObject

Specifies the objects to convert to JSON format. Enter a variable that contains the objects, or type a command or expression that gets the objects. You can also pipe an object to ConvertTo-JsonForPSWS.

The InputObject parameter is required, but its value can be null ($Null) or an empty string. When the input object is $Null, ConvertTo-JsonForPSWS does not generate any output. When the input object is an empty string, ConvertTo-JsonForPSWS returns an empty string.

Type:Object
Position:0
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False
Applies to:Skype for Business Online

Inputs

System.Object

You can pipe any object to ConvertTo-JsonForPSWS.

Outputs

System.String