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)