2013-05-14 35 views
1

我正在處理一個powershell腳本,在做了一些事情後,應該啓動基於用戶AD組成員身份的三個應用程序之一。我無法加載AD模塊,所以我用gpresult.exe /r相當於gpresult/r與powershell沒有廣告模塊

$temp = gpresult.exe /r 
if ($temp -match "myAdGroup") { ... } 

是否有一個PowerShell命令,以更有效地做同樣的事情?

回答

4

一個方法是:

$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() 
$WindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($CurrentUser) 

if($WindowsPrincipal.IsInRole("myAdGroup")) 
{ 
    ... 
} 
else 
{ 
    ... 
} 
+0

它完美的作品,謝謝! – Naigel 2013-05-14 14:57:09