2015-03-31 53 views
0

我們有一個包含和不包含信任的不同域和森林的環境。需要腳本來查找服務器激活狀態

我需要管理這些出KMS的許可證。

我想找出正在運行的服務器沒有激活或寬限期。

我一直在嘗試使用WMIC和Powershell的不同腳本。但是,無法清晰乾淨地生成。

以下是試過的腳本。我需要這方面的幫助。

從WMIC:

WMIC /Output:@D:\output.txt /node:@D:\serverslist.txt PATH SoftwareLicensingProduct WHERE "ProductKeyID like '%-%' AND Description like '%Windows%'" get LicenseStatus 

從Powershell的:

PS C:\Windows\system32> Get-CimInstance -ClassName SoftwareLicensingProduct |where PartialProductKey |select PScomputername,LicenseStatus 

我需要幫助生成計算機名/ IP和許可狀態的表。

在此先感謝。

+0

閱讀此[鏈接](https://technet.microsoft.com/en-us/magazine/2008.06.windowspowershell.aspx)您可以創建psobject然後加上列和值 – powershell 2015-03-31 12:47:16

回答

1

在這裏,我只是做了一些調整。

其一,你的代碼返回LICENSESTATUS的數... ...這是確定的,但要獲得一些真正哇因素,我諮詢this chart from MSDN on what the numbers mean,並且使用了與switch語句中,計算方法爲物業內更換與人類有意義的許可狀態號碼,給我們這樣的邏輯:

select Pscomputername,Name,@{Name='LicenseStatus';Exp={ 

switch ($_.LicenseStatus) 
{ 
0 {'Unlicensed'} 
1 {'licensed'} 
2 {'OOBGrace'} 
3 {'OOTGrace'} 
4 {'NonGenuineGrace'} 
5 {'Notification'} 
6 {'ExtendedGrace'} 
Default {'Undetected'} 
} 
#EndofCalulatedProperty 
}} 

這給我們完整的代碼,這樣,也提取產品的名稱爲好。你可以僅僅通過增加他們的名字-ComputerName財產對多個系統運行此:

Get-CimInstance -ClassName SoftwareLicensingProduct -computerName localhost,dc01,windows10 | 
    where PartialProductKey | select Pscomputername,Name,@{Name='LicenseStatus';Exp={ 
     switch ($_.LicenseStatus) 
     { 
    0 {'Unlicensed'} 
    1 {'licensed'} 
    2 {'OOBGrace'} 
    3 {'OOTGrace'} 
    4 {'NonGenuineGrace'} 
    5 {'Notification'} 
    6 {'ExtendedGrace'} 
    Default {'Undetected'} 
} 
#EndOfCaltulatedProperty 
}} 

這給你的結果是這樣的:

PSComputerName       Name         LicenseStatus       
--------------       ----         -------------       
localhost        Office 15, OfficeProPlusVL_MAK edition licensed        
localhost        Windows(R), ServerDatacenter edition licensed 
dc01         Windows(R), ServerStandard edition  licensed 
Windows10        Windows(R), ServerStandard edition  licensed 
+0

該腳本非常完美,但由於在WINRM中設置了記錄,無法運行遠程計算機和IP地址。我只是爲了爭取它而戰鬥。一旦我修好了會更新你。謝謝 – 2015-04-01 14:40:45

+0

如果你想在整個環境中運行它,你需要打開PowerShell遠程處理。您可以爲整個公司使用組策略,或者您可以通過Admin PowerShell提示「Enable-PSRemoting -Force」一次完成一臺PC。 – FoxDeploy 2015-04-01 15:01:23

+0

我嘗試了許多啓用psremoting的功能,在winrm中啓用Https創建自簽名和分配的證書,爲所有人啓用可信列表。無法通過它。計劃使用域憑據在單個域上運行,就像您一樣,並且會更新您......感謝 – 2015-04-02 06:09:08

0
Get-CimInstance -ClassName SoftwareLicensingProduct | 
where PartialProductKey | 
select Name, ApplicationId, LicenseStatus 
1

,你也可以嘗試

$activation  = (Get-CimInstance -ClassName SoftwareLicensingProduct | where ApplicationId -EQ 55c92734-d682-4d71-983e-d6ec3f16059f | where PartialProductKey).LicenseStatus 
相關問題