【问题标题】:Using Powershell Get-ItemProperty through all of AD computers object通过所有 AD 计算机对象使用 Powershell Get-ItemProperty
【发布时间】:2021-09-19 17:03:15
【问题描述】:

我是 Powershell 的新手(和您可能已经猜到的编程),我想为我们的每个 AD 计算机对象获取以下 PS 命令的结果,并将结果打印到文本文件中...但我完全迷路了。有人有我可以坚持的生命线吗?

Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-String -Pattern "mysoftwarename"

非常感谢。

【问题讨论】:

    标签: powershell foreach active-directory


    【解决方案1】:
    $ScriptBlock = {Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-String -Pattern "mysoftwarename"}
    $Computers = (Get-ADComputers -filter * ).name
    $Creds = (Get-Credential)
    
    foreach ($Computer in $Computers)
    {
        "`n`n$Computer`n" >> .\file.txt # "`n" just emulates Enter key press
        Invoke-Command -ComputerName $Computer -ScriptBlock $ScriptBlock -Credential $Creds >> .\file.txt
    }
    

    如果您的所有计算机都在线并且正确配置了 PS 远程处理,这将正常工作。否则,将需要修改。

    【讨论】:

    • 非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多