我正在編寫工作腳本並試圖確定爲什麼我的代碼顯示錯誤。我是這種編碼的新手,並且想要了解什麼是錯誤的。爲AD PC列出AD組的錯誤
我得到的錯誤來自標籤....我的.txt文件中的PC列表。
例如:Get-Content:找不到路徑'F:\ tag 77909',因爲它不存在。 我的困惑是,當我編寫主機後.Replace代碼打印正確
例如:你不能調用一個空值表達式的方法。 + $ Notags = $ PC.Replace < < < <( 「標籤」, 「PC」) + CategoryInfo:InvalidOperation:(更換:字符串)[],RuntimeEx ception + FullyQualifiedErrorId:InvokeMethodOnNull
最後一個錯誤我得到的是,它只打印出我的.txt文件列表中的最後一個PC .... ID。我不確定爲什麼給我有一個foreach循環
**MY CODE SO FAR:**
Import-Module activedirectory
$compImports = Get-Content "C:\Temp\temp\input.txt"
$groupExport = "C:\temp\temp\output.txt"
Clear-Content $groupExport
$Header = "PC Name" + "|" + "Group Name" + "|" + "Group Description"
#Write header
$Header | Out-File $groupExport -Append
#get PC tag listing
$PCs = Get-Content $compImports
#For loop to change all "tag " to "PC"
foreach($PC in $PCS)
{
$Notags =$PC.Replace("tag ", "PC")
}
#loop to get information and print it out
foreach ($Notag in $Notags) {
$computerobj = Get-ADComputer $Notag -Properties memberof
$computerobj.memberof | ? {$_ -match '^CN=APP.*'} `
| % {get-adgroup $_ -Properties name, description} | `
% {$computerobj.Name + "|" + $_.name + "|" + $_.description `
| Out-File $groupExport -Append}
}
文本文件是否只包含「tag 77909」這樣的項目? – Matt 2014-09-10 17:48:11
是的。但是,我發現我的錯誤。謝謝 – narue1992 2014-09-10 17:57:01