2013-09-23 79 views
3

我知道Get-WSManCredSSP函數;但是,此cmdlet在腳本中效果不佳。這將返回類似於下面的長字符串:有沒有簡單的方法來檢查系統上是否啓用了CredSSP?

The machine is configured to allow delegating fresh credentials to the following target(s): wsman/*,wsman/*,wsman/*,wsman/* 
This computer is configured to receive credentials from a remote client computer. 

我不能輕易包括這是我寫一個劇本,所以我在尋找一種替代的方法來檢查的CredSSP。

回答

2

您不能考慮按照CmdLet help中的說明使用它:獲取客戶端上的WS-Management CredSSP設置(<localhost|computername>\Client\Auth\CredSSP)。

在本地機器它給出:

(Get-Item WSMan:\localhost\Client\Auth\CredSSP).value 

您可以使用它像這樣:

(Get-Item WSMan:\localhost\Client\Auth\CredSSP).value -eq $false 

你可以先測試,如果WinRM的可用:

(Get-Service -Name winrm).Status 
+0

值得一提的是,這是對客戶端啓用的CredSSP。如果要檢查服務器啓用的CredSSP,請使用以下內容: (Get-Item WSMan:\ localhost \ Service \ Auth \ CredSSP).value – Anthony

2

我也在努力處理Get-WSManCredSSP輸出的侷限性,並發現了Victor的this helper script Vogelpoel/Ravikanth Chaganti會非常有幫助。

一些例子:

檢查當前機器已被配置爲CredSSP的服務器和/或客戶端:

(Get-WSManCredSSPConfiguration).IsServer 
(Get-WSManCredSSPConfiguration).IsClient 

檢查指定的客戶端機器已經成立了代表團:

Get-WSManCredSSPConfiguration | % { $_.ClientDelegateComputer.Contains('clientcomputername') } 
0

(不打算替代Vogelpoel & Chaganti的工作,但作爲快速閱讀CredSSP.cs的快速總結,所以你可以得到什麼它做一個快速的掌握 - 這麼說,這是在幾個系統我在手上測試,似乎工作)

function Get-WSManCredSSPState 
{ 
    $res = [pscustomobject]@{DelegateTo = @(); ReceiveFromRemote = $false} 

    $wsmTypes = [ordered]@{} 
    (gcm Get-WSManCredSSP).ImplementingType.Assembly.ExportedTypes ` 
    | %{$wsmTypes[$_.Name] = $_} 

    $wmc = new-object $wsmTypes.WSManClass.FullName 
    $wms = $wsmTypes.IWSManEx.GetMethod('CreateSession').Invoke($wmc, @($null,0,$null)) 
    $cli = $wsmTypes.IWSManSession.GetMethod('Get').Invoke($wms, @("winrm/config/client/auth", 0)) 
    $res.ReceiveFromRemote = [bool]([xml]$cli).Auth.CredSSP 

    $afcPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation\AllowFreshCredentials' 
    if (test-path $afcPath) 
    { 
    $afc = gi $afcPath 
    $res.DelegateTo = $afc.GetValueNames() | sls '^\d+$' | %{$afc.GetValue($_)} 
    } 
    return $res 
} 
相關問題