Solved

Powershell indicate users missing attribute "homeDirectory"

Posted on 2014-09-15
8
547 Views
Last Modified: 2014-09-16
Hi,

Please assist creating a powershell script that searches all users in a specific OU and indicates which of those users are missing the "homeDirectory" attribute.

Thanks
0
Comment
Question by:antmax00
  • 3
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40323609
Import-Module ActiveDirectory
Get-ADUser $_ -properties DisplayName,HomeDirectory | Select DisplayName,HomeDirectory | where {$_.homedirectory -eq $null or $_.homedirectory -eq ""}  | Export-CSV c:\file.csv -nti

Open in new window

                                         
Something like above should work.

Updated
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40323827
You need to use -SearchBase parameter to search in specific OU. In below example C:\homedirectory.csv will have details of users who are missing homedirectory attribute from OU "OU=Personnel,DC=Domain,DC=COM"
Import-Module Activedirectory
Get-ADUser -Filter * -SearchBase "OU=Personnel,DC=Domain,DC=COM" | ?{!($_.homedirectory)} | Export-csv C:\homedirectory.csv -nti

Open in new window

0
 

Author Comment

by:antmax00
ID: 40326532
becraig, your script gives an error
PS C:\Windows\system32> Import-Module ActiveDirectory
Get-ADUser $_ -properties DisplayName,HomeDirectory | Select DisplayName,HomeDirectory | where {$_.homedirectory -eq $null or $_.homedirectory -eq ""}  
At line:2 char:124
+ ... tory -eq $null or $_.homedirectory -eq ""}
+                    ~~
Unexpected token 'or' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
 

Open in new window

0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 40

Expert Comment

by:Subsun
ID: 40326547
@antmax00, Did you try my code?
0
 

Author Comment

by:antmax00
ID: 40326548
subsun, your script shows users that have and don't have a 'homedirectory'
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40326573
OK I found it.. I missed the -pr HomeDirectory in the code which i posted..
Import-Module Activedirectory
Get-ADUser -Filter * -SearchBase "OU=Personnel,DC=Domain,DC=COM" -pr HomeDirectory | ?{!($_.homedirectory)} | Export-csv C:\homedirectory.csv -nti

Open in new window

or
Import-Module Activedirectory
Get-ADUser -Filter * -SearchBase "OU=Personnel,DC=Domain,DC=COM" -pr HomeDirectory | ?{$_.homedirectory -eq $null -or $_.homedirectory -eq ""} | Export-csv C:\homedirectory.csv -nti

Open in new window

0
 
LVL 29

Expert Comment

by:becraig
ID: 40326705
For mine you'd just change or to "-or".
0
 

Author Comment

by:antmax00
ID: 40326718
Subsun, great. That works!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question