Solved

Powershell indicate users missing attribute "homeDirectory"

Posted on 2014-09-15
8
530 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
 
LVL 40

Expert Comment

by:Subsun
ID: 40326547
@antmax00, Did you try my code?
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

919 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

18 Experts available now in Live!

Get 1:1 Help Now