Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Get-ADuser Help

$
0
0

Hi, i have a list of Userhome folders in a server so i need to delete the ones where the users in AD are disabled or are in a specific leavers OU. But i got something wrong with my code.

First i get the userhome folders which are equal to the username

import-module activedirectory

$homefolders = Get-ChildItem \\server1\e$\homefolders

This get me the correct object like:

Mode                LastWriteTime     Length Name                                                                                                                                                                         
----                -------------     ------ ----                                                                                                                                                                         
d----         9/19/2013   8:40 PM            user1                                                                                                                                                                       
d-r--         9/20/2013   5:18 AM            user2

Then i do a get-ad user for each foldername (which is the same as the username) to see if they are disabled and in the OU, but i get nothing...

foreach ($homefolder in $homefolders) {

$user = Get-ADUser $homefolder.name -SearchBase "OU=leavers,DC=contoso,DC=com" -Properties homedirectory | where { $_.enabled -eq $false -and $_.homedirectory -like "*server1*" }

}


$homefolder.name contains the proper username but when i run it i get the error

Get-ADUser : A positional parameter cannot be found that accepts argument 'user1'

   + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Why is this failing?

Thanks



Viewing all articles
Browse latest Browse all 21975

Trending Articles



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