Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Delete User pofile if no longet in Active Directory

$
0
0

I am trying to come up with a solution to list the users in the local admin group on a list of servers. and select only user with names like UN12345. then check active directory to see if the account still exists. if not remove the account and profile from the server. I can dump the users into a text file but when I try and do the attached. it just parses through all accounts in AD. not the ones in my file.

Powershell
Get-Content-PathC:\Temp\test\myserver.admins.txt|ForEach-Object{Get-ADUser-LDAPFilter"(samaccountname=$_)"|Select-Object-Propertysamaccountname,enabled-ErrorActionStop}


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>