首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >将函数的值拉到变量中

将函数的值拉到变量中
EN

Stack Overflow用户
提问于 2014-10-19 20:07:28
回答 1查看 44关注 0票数 0

函数Get-loggedOnUser显示了3项,代码可以在这里找到LoggedInUser

  1. 计算机名称
  2. 登录用户
  3. 用户的Sid

我希望能够获得LoggedOnUser函数的结果(只需要登录用户),并将结果输送到名为Username的变量中。

代码语言:javascript
运行
复制
    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
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-19 20:27:08

代码语言:javascript
运行
复制
$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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26454875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档