Output is in Json format (Convertto-json)

Source: Internet
Author: User

1. Direct output to JSON format:

get-Process$pid  | Convertto-json | Clip.exe

2. Custom results are in JSON format:

 $serverinfoj= @"              {                    "Status": "Success",                    "Infors": {                            "ServerName": "$env: ComputerName",                            "Ip": "$Server",                            "OSVersion": "$osversion",                            "Memorysize": "$memorysize _sum",                            "Cpu": "$cpunamecore",                            "DomainName": "$domainname",                            "DISK": "$disklist",                            "SN": "$SN",                            "Xinghao":"$xinghao"                           }                 }"@#The format must be this way, shelf write, start and end @ cannot be written to a line with curly braces#the contents of the variables must also be caused .$serverinfo= Convertfrom-json-inputobject$serverinfoj #转换为json格式$serverinfo. Status$serverinfo. Infors$serverinfo. Infors.osversion

#Output Result:servername:pc-LIP:10.16.30.51osversion:microsoft Windows Server2012R2 Datacenter 64bitmemorysize:4gbcpu:intel (R) Xeon (r) CPU E5-2620 v3 @ 2.40GHz1CDOMAINNAME:UXIN.YOUXINPAI.COMDISK:DISK0:300GB Sn:hyper-vxinghao:microsoft Virtual machinemicrosoft Windows ServerR2 Datacenter 64bit

You can also make changes to $serverinfo content, such as:

$serverinfo. Status = "Test"

Value can also be obtained directly from the command, using the $ symbol

$json= @"{    "ServerName": "$env: ComputerName",    "Bios": {         "SN" : "$ ((Get-wmiobject-class Win32_BIOS). SN)",         "Version" : "$ ((Get-wmiobject-class Win32_BIOS). Version)"         },    "OS" : "$ ([environment]::osversion.versionstring)" }"@

Output is in Json format (Convertto-json)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.