2014-10-19 48 views
0

功能獲取-loggedOnUser顯示了3個項目,並且代碼可以在這裏找到LoggedInUser拉動功能的值到變量

  1. 計算機名稱
  2. 登錄的用戶
  3. 希德用戶

我希望能夠取得LoggedOnUser函數的結果(只需要登錄的用戶)並將結果傳遞給下面稱爲用戶名的變量。

Import-Module ActiveDirectory 
    function Get-LoggedOnUser 

    $credential = Get-Credential 
    $computers = "MachineName" 

    foreach ($machine in $computers) 
    { 
    Get-LoggedOnUser -ComputerName $machine 
    $username = $_.LoggedOn 
    $sid = ((get-aduser $username).SID).Value 

    Invoke-Command -ComputerName $machine -Credential $credential -ScriptBlock { New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS; New-ItemProperty -Path "HKU:\$($args[0])\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -PropertyType String -Name AutoConfigURL -Value "http://proxy.domain.com/proxies/proxy.pac" -Force } -argumentlist $sid 
    } 

回答

0
$loggedOn=Get-LoggedOnUser -computername $machine 
$username = $loggedOn.LoggedOn 
$sid = $loggedOn.Sid #as this is already returned from above funtion 
$sid = ((get-aduser $username).sid).value #if you want to still get it from AD 
+0

感謝您的幫助! – NobleMan 2014-10-19 23:35:51