Solved

Powershell indicate users missing attribute "homeDirectory"

Posted on 2014-09-15
8
573 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …

734 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