-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDelete-ADComputer.ps1
More file actions
66 lines (31 loc) · 1.08 KB
/
Delete-ADComputer.ps1
File metadata and controls
66 lines (31 loc) · 1.08 KB
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
56
57
58
59
60
61
62
63
64
65
66
Import-module activedirectory
Set-location AD:
#Write an "Are you sure" option.
#assign Get-location to the variable $local
$local = Get-Location
#While the path of local is not equal to AD:\ go up a directory and update the location for variable $local
$HN = Import-csv C:\CSV\DeletefromAD.csv
$HN
$Choice = Read-Host "Are you Sure you want to Delete these? "
if($Choice -eq "Yes" -or "Y" -or "1"){
while($local.path -ne "AD:\"){
cd ..
$local = Get-Location
$local.path
}
Set-location "OU=US_Excelsior_Medical_Neptune_NJ,OU=Users_And_Computers,DC=medline,DC=com"
ForEach ($HNs in $HN){
$tc = test-connection $Hns.Hostname -quiet -count 1
if($tc -eq $False){
Try{
Remove-Adcomputer -Identity $HNs.Hostname -ErrorAction Stop
}
catch [System.Exception] {
Write-host "$($HNs.Hostname) Doesn't exist"
}
}
}
}else{
"Aborted"
}
Push-location C:\Powershell-Repository