Solved

Powershell indicate users missing attribute "homeDirectory"

Posted on 2014-09-15
8
500 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 28

Expert Comment

by:becraig
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
@antmax00, Did you try my code?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
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 28

Expert Comment

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

Author Comment

by:antmax00
Comment Utility
Subsun, great. That works!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now