使用powershell

时间:2018-04-25 05:25:32

标签: powershell powershell-v2.0 powershell-v3.0

我在文本文件中有1000个JSON对象。我想使用PowerShell为特定的duns号码只检索一个JSON对象。

{
   "organization":{
      "duns":"024330410",
      "dunsControlStatus":{
         "operatingStatus":{
            "description":"Active",
            "dnbCode":9074
         },
         "isMarketable":false,
         "isMailUndeliverable":false,
         "isTelephoneDisconnected":null,
         "isDelisted":false,
         "subjectHandlingDetails":[

         ],
         "fullReportDate":"2018-02-10"
      },
      "primaryName":"SRP Trucking LLC",
      "multilingualPrimaryName":[

      ],
      "tradeStyleNames":[

      ],
      "websiteAddress":[

      ],
      "telephone":[

      ],
      "fax":[

      ],
      "primaryAddress":{
         "language":{

         },
         "addressCountry":{
            "name":"United States",
            "isoAlpha2Code":"US",
            "fipsCode":"US"
         },
         "continentalRegion":{
            "name":"North America"
         },
         "addressLocality":{
            "name":"LAKE HAVASU CITY"
         },
         "minorTownName":null,
         "addressRegion":{
            "name":"Arizona",
            "abbreviatedName":"AZ",
            "fipsCode":"04"
         },
         "addressCounty":{
            "name":"MOHAVE",
            "fipsCode":"015"
         },
         "postalCode":"864035343",
         "postalCodePosition":{

         },
         "streetNumber":null,
         "streetName":null,
         "streetAddress":{
            "line1":"25 SOUTHWESTER LN",
            "line2":null
         },
         "postOfficeBox":{

         },
         "latitude":34.488798,
         "longitude":-114.301529,
         "geographicalPrecision":{
            "description":"Street Address Centroid",
            "dnbCode":30257
         },
         "isRegisteredAddress":false,
         "isResidentialAddress":null,
         "statisticalArea":{
            "cbsaName":"Lake Havasu City-Kingman AZ",
            "cbsaCode":"29420",
            "economicAreaOfInfluenceCode":"092",
            "populationRank":{
               "rankNumber":"7",
               "rankDnBCode":10959,
               "rankDescription":"100,000 to 249,999"
            }
         },
         "locationOwnership":{

         },
         "premisesArea":{
            "measurement":2915.0,
            "unitDescription":"Square Foot",
            "unitDnBCode":3848,
            "reliabilityDescription":"Modelled",
            "reliabilityDnBCode":9094
         },
         "isManufacturingLocation":null
      },
      "multilingualPrimaryAddress":[

      ],
      "registeredAddress":{

      },
      "mailingAddress":{

      },
      "stockExchanges":[

      ],
      "thirdPartyAssessment":[

      ],
      "registrationNumbers":[

      ],
      "industryCodes":[
         {
            "code":"484110",
            "description":"General Freight Trucking, Local",
            "typeDescription":"North American Industry Classification System 2017",
            "typeDnBCode":30832,
            "priority":1
         },
         {
            "code":"1622",
            "description":"Trucking",
            "typeDescription":"D&B Hoovers Industry Code",
            "typeDnBCode":25838,
            "priority":1
         },
         {
            "code":"4212",
            "description":"Local trucking operator",
            "typeDescription":"US Standard Industry Code 1987 - 4 digit",
            "typeDnBCode":399,
            "priority":1
         },
         {
            "code":"42120000",
            "description":"Local trucking, without storage",
            "typeDescription":"D&B Standard Industry Code",
            "typeDnBCode":3599,
            "priority":1
         },
         {
            "code":"E",
            "description":"Transportation, Communications, Electric, Gas and Sanitary Services",
            "typeDescription":"D&B Standard Major Industry Code",
            "typeDnBCode":24657,
            "priority":1
         }
      ],
      "businessEntityType":{
         "description":"Unknown",
         "dnbCode":0
      },
      "controlOwnershipDate":"2015",
      "startDate":"2015",
      "controlOwnershipType":{

      },
      "isAgent":null,
      "isImporter":null,
      "isExporter":null,
      "numberOfEmployees":[
         {
            "value":1,
            "informationScopeDescription":"Consolidated",
            "informationScopeDnBCode":9067,
            "reliabilityDescription":"Modelled",
            "reliabilityDnBCode":9094,
            "employeeCategories":[

            ],
            "trend":[

            ]
         },
         {
            "value":1,
            "informationScopeDescription":"Individual",
            "informationScopeDnBCode":9066,
            "reliabilityDescription":"Modelled",
            "reliabilityDnBCode":9094,
            "employeeCategories":[

            ],
            "trend":[

            ]
         }
      ],
      "financials":[
         {
            "financialStatementToDate":"2016-10-01",
            "financialStatementDuration":null,
            "informationScopeDescription":null,
            "informationScopeDnBCode":null,
            "reliabilityDescription":"Modelled",
            "reliabilityDnBCode":9094,
            "unitCode":"Single Units",
            "accountantName":null,
            "yearlyRevenue":[
               {
                  "value":57815.0,
                  "currency":"USD",
                  "trend":[

                  ]
               }
            ]
         }
      ],
      "mostSeniorPrincipals":[
         {
            "givenName":"Debbie",
            "familyName":"Pickering",
            "fullName":"Debbie Pickering",
            "namePrefix":null,
            "nameSuffix":null,
            "gender":null,
            "jobTitles":[
               {
                  "title":"Owner"
               }
            ],
            "managementResponsibilities":[
               {
                  "description":"Owner",
                  "mrcCode":"A0A1"
               }
            ]
         }
      ],
      "currentPrincipals":[

      ],
      "socioEconomicInformation":{
         "isMinorityOwned":null,
         "isSmallBusiness":true
      },
      "isStandalone":true,
      "corporateLinkage":{

      }
   }
}

1 个答案:

答案 0 :(得分:0)

PS直接使用可以满足您目的的JSON cmdlet:

将变量中的JSON字符串作为 $ variable1 ,然后使用:

$variable1 | ConvertFrom-Json

以后您可以使用Convertto-Json将其转换为JSON where-object

希望它有所帮助。刚刚形成了Tomalak的答案