【问题标题】:List Computers with a Specific Folder Using Powershell使用 Powershell 列出具有特定文件夹的计算机
【发布时间】:2014-06-25 21:44:24
【问题描述】:

我正在尝试创建安装了程序测试版本的 AD 计算机清单。该程序不会在 Windows 程序列表中创建条目,它只是在公共用户文件夹中创建一个文件夹。出于多种原因,如果我可以轮询 AD 以获取计算机列表,然后在公共用户中搜索“测试”文件夹,那就太好了。

这是我想出来的,但当然失败了,因为我是新手。

Get-ADComputer -Filter * | Get-ChildItem -path 'C:\Users\Public\Program\Test | Export-Csv \\computer\Users\Daren\Desktop\testfolder.csv

这是有人在另一个板上发布此问题后编写的更好的脚本,但输出是空白的,他们没有告诉我如何解决它。

$computers = get-adcomputer -filter *

$output = @()

ForEach ($computer in $computers) {

If(Test-Path -Path "\\$($computer.Name)\c$\Users\Public\path\test") {

    $output += $computer

    }

}

$output | Export-Csv -NoTypeInformation -Path .\test.csv

欢迎并感谢所有输入!

【问题讨论】:

    标签: powershell directory inventory


    【解决方案1】:

    可能是这样的:

    get-adcomputer -filter * | foreach-object {
      $computerName = $_.Name
      if ( test-path "\\$computerName\C$\Users\Public\path\test" ) {
        $computerName
      }
    } | out-file list.txt
    

    或者:

    get-adobject -ldapfilter "(objectClass=computer)" | foreach-object {
      $computerName = $_.Name
      if ( test-path "\\$computerName\C$\Users\Public\path\test" ) {
        $computerName
      }
    }
    

    【讨论】:

    • 比尔,非常感谢您的快速回复!我现在正在测试,并将报告我的发现。
    • 输出文件又是空白!我很困惑。
    • 这是我得到的错误:get-adcomputer:服务器返回了以下错误:无效的枚举上下文。在 line:1 char:1 + get-adcomputer -filter * | foreach-object { + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:0 ,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
    • @Dazza - 尝试替代答案。
    • Bill,非常感谢您的帮助,但是我收到与以前类似的错误:get-adobject:服务器返回以下错误:无效的枚举上下文。在 line:1 char:1 + get-adobject -ldapfilter "(objectClass=computer)" | foreach-object { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADObject], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADObject
    猜你喜欢
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2018-08-13
    • 2015-11-28
    • 2013-01-20
    • 2019-09-07
    • 2017-12-06
    • 2015-06-27
    相关资源
    最近更新 更多