?
Solved

Powershell indicate users missing attribute "homeDirectory"

Posted on 2014-09-15
8
Medium Priority
?
613 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
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 …
Suggested Courses

771 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