-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAD_Clear_Attributes_With_Spaces.ps1
55 lines (43 loc) · 1.96 KB
/
AD_Clear_Attributes_With_Spaces.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Search in a remote AD Domain for attributes with spaces...
$DC= "DC01.CONTOSSO.COM"
$LDAP = "dc=contosso,dc=com"
$account = "CONTOSSO\SVC_MIMADMA"
$pwd = read-host "Enter the password for $account "
$attribute = read-host "Enter the attribute:"
write-host "facsimileTelephoneNumber"
write-host "department"
write-host ""
write-host ""
#############################################################################
# Establish connection to remote directory
#############################################################################
$domainInfo = New-Object DirectoryServices.DirectoryEntry("LDAP://$dc/$ldap",$account,$pwd)
$Searcher = New-Object DirectoryServices.DirectorySearcher($domainInfo)
$Searcher.PageSize=150000
$Searcher.SearchScope = "Subtree"
$Searcher.filter = "(&($attribute=\20))"
#############################################################################
# Initiate search
#############################################################################
$colResults = $Searcher.FindAll()
write-host "###################################################"
write-host "Total objects: $($colresults.Count)"
write-host "###################################################"
#############################################################################
# Enumerate search results
#############################################################################
foreach ($objResult in $colResults)
{
[String] $strLine = $null
$strLine = "$($objresult.Path)"
$strLine = $($strLine.Replace("$dc/",""))
Add-Content "C:\code\Scripts\EmptyString_$attribute.txt" "$strLine`t$attribute"
$de = new-Object DirectoryServices.directoryEntry($strLine,$account,$pwd)
#Write-Host "Parent Path: $($de.Parent)"
#############################################################################
# Clear values
#############################################################################
#$de.putex(1,"$attribute",$null)
#$de.SetInfo()
$de.Dispose()
}