簡體   English   中英

PowerShell腳本可排除在AD中被禁用的計算機列表

[英]PowerShell script to exclude a list of computers from getting disabled in AD

你們能在以下情況下幫助我嗎? 這就是我要完成的工作。

  1. 我生成需要在AD = file1.txt中禁用的計算機的報告

  2. 我有一個預制的計算機列表,可以從禁用列表中排除= file2.txt

  3. 我有一個腳本可以從文本文件中禁用計算機列表,但是我想排除file2.txt中存在的任何計算機。

這是我到目前為止所擁有的

$toBeDisabled = Import-CSV \\SERVER\file1.csv

$ toBeExcluded =導入CSV \\ SERVER \\ file2.csv

$ toBeDisabled = $ toBeExcluded | 位置對象{($ toBeExcluded |選擇對象-擴展屬性名稱)-不包含$ _。Name}

ForEach($ toBeDisabled.DeviceName中的$ Computer)

{$ Computer = $ Computer.Trim()

$ADComputer = Get-ADComputer $Computer -Properties Description

如果($ ADComputer)

{添加內容c:\\ temp \\ computers.log -Value“已找到並禁用了以下PC $ Computer”

Set-ADComputer $ ADComputer-說明“ $($ ADComputer.Description)-由於不活動而禁用-$(Get-Date)-通過$ env:UserName” -Enabled $ False

}

其他

{添加內容c:\\ temp \\ computers.log-值“ $ Computer在Active Directory中找不到或之前被禁用”

}

}

我收到以下錯誤(找不到選擇對象:屬性“名稱”)

謝謝

最好的方法是先比較這兩個文件:

$toBeExcluded = Import-Csv C:\temp\file2.csv
$toBeDisabled = $toBeExcluded | Where-Object {($toBeExcluded | Select-Object -ExpandProperty Name) -NotContains $_.Name}

上面假設file2.csv具有相同的格式(因此具有屬性Name )。

然后,只需在foreach使用$toBeDisabled而不是$Computers即可。

我知道了。

比較對象$ file1 $ file2-屬性“ DeviceName” | 其中SideIndicator -eq“ <=” | 選擇設備名稱| 導出Csv“ \\ Server \\ DisableList.csv” -NoType

謝謝大家的幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM