【发布时间】:2018-08-11 04:17:25
【问题描述】:
我正在尝试清理
的输出cscript 'C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs' /dstatus
我只想显示许可证和密钥的最后 5 个字符,例如
Office16HomeBusinessR_Retail3 版,7H67X
我有它的一部分,但不能完全组合在一起。
$comp = "Computername"
$OfficLice = "C:\share\OfficLice.csv"
$localtemp = "C:\share\OfficLiceTemp.csv"
cscript 'C:\Program Files (x86)\Microsoft Office\Office16\ospp.vbs' /dstatus $comp | add-content $localtemp
$lic = get-content $localtemp | where {$_ -like "LICENSE NAME*"}
$key = get-content $localtemp | where {$_ -like "Last 5*"}
$key = foreach ($item in $key){
($item -split ' ')[7]}
foreach ($item in $lic){
($item -split ' ')[4] | add-content -Path $OfficLice.("License Name")
}
foreach ($item in $key){
$item | add-content -Path $OfficLice.Key
}
这是我正在尝试清理的内容的副本
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
---Processing--------------------------
---------------------------------------
PRODUCT ID: 00333-59056-17787-AA631
SKU ID: 522f8458-7d49-42ff-a93b-670f6b6176ae
LICENSE NAME: Office 16, Office16HomeBusinessR_Retail3 edition
LICENSE DESCRIPTION: Office 16, RETAIL channel
LICENSE STATUS: ---LICENSED---
Last 5 characters of installed product key: 7H67X
---------------------------------------
PRODUCT ID: 00340-00000-00000-AA482
SKU ID: 971cd368-f2e1-49c1-aedd-330909ce18b6
LICENSE NAME: Office 16, Office16SkypeforBusinessEntryR_PrepidBypass edition
LICENSE DESCRIPTION: Office 16, RETAIL(Free) channel
LICENSE STATUS: ---LICENSED---
ERROR CODE: 0x4004FC05 (for information purposes only as the status is licensed)
ERROR DESCRIPTION: The Software Licensing Service reported that the application has a perpetual grace period.
Last 5 characters of installed product key: HT9YM
---------------------------------------
PRODUCT ID: 00198-20000-00000-AA054
SKU ID: ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d
LICENSE NAME: Office 15, OfficeLyncEntryR_PrepidBypass edition
LICENSE DESCRIPTION: Office 15, RETAIL(Free) channel
LICENSE STATUS: ---LICENSED---
ERROR CODE: 0x4004FC05 (for information purposes only as the status is licensed)
ERROR DESCRIPTION: The Software Licensing Service reported that the application has a perpetual grace period.
Last 5 characters of installed product key: BPW98
---------------------------------------
---------------------------------------
---Exiting-----------------------------
【问题讨论】:
标签: powershell csv scripting text-parsing