?
Solved

Checking user profiles

Posted on 2009-04-24
11
Medium Priority
?
965 Views
Last Modified: 2012-08-13
I need your help on powershell comands:
- i need to query remote pc searching information about specific user: the profile is local, roaming or n/a ?
- i need to search in a specific path for a specific directory: is it present? is it empty?

Thanks in advance!
0
Comment
Question by:strivoli
  • 5
  • 4
9 Comments
 
LVL 20

Author Comment

by:strivoli
ID: 24239689
Get-QADUser "user" | fl *Profile*

with this command i can see user profile in AD;

now i need to serch if path is empty: any advice will be appreciated.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24239749

I can help with that bit at least ;)

This should work on a simple level:


If (Get-QADUser "User" -ProfilePath *) {
  Write-Host $_ | Select Name, DN, ProfilePath
} else {
  Write-Host "No Profile"
}

To search for all users with it empty, this will work:

Get-QADUser -LdapFilter "(!profilePath=*)"

Chris
0
 
LVL 20

Author Comment

by:strivoli
ID: 24240891
Thanks Cris-Dent but i need other informations;

with "Get-QADUser "user" | fl *Profile*" I get both profile path ( ProfilePath, TsProfilePath );
now i need to search inside both:
- are they empty?
- if not is there Document folder?is it empty?

Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 71

Expert Comment

by:Chris Dent
ID: 24240929

Well, you could do it like this:

$ADUser = Get-QADUser "user"
If ($ADUser.ProfilePath) {
  Write-host "Profile Path: $($ADUser.ProfilePath)"
}
If ($ADUser.TsProfilePath) {
  Write-Host "TS Profile Path: $($ADUser.TsProfilePath)"
}

But you could see as much if you just did:

Get-QADUser "user" | Select-Object Name, ProfilePath, TsProfilePath

I guess you're trying to wrap code around that lot though?

> - if not is there Document folder?

Where would it be? On the system running the command?

Chris
0
 
LVL 20

Author Comment

by:strivoli
ID: 24248501
OK Cris-Dent,
the result is:
ProfilePath: \\srvr-file1\winprofiles$\user
TSProfilePath: \\srvr-file1\TSwinprofiles$\user

Now i need to check inside the 2 path if there is a particular directory and if it has been populated with files or directory.

Thanks
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24248667

Fair enough.

Lets pop a function in to do the search for us. Otherwise we have to repeat the code if we keep the current format which is messy.

Chris
$DirectoryName = "SomeFolderName"
$ADUser = Get-QADUser "user"
 
Function FindDirectory {
  Param($Name, $Path)
 
  Get-ChildItem $Path -Recurse | ?{ $_.Name -eq $Name -And $_.PsIsContainer -eq $True } | %{ 
    Write-Host "$Name exists at $($_.FullName)" 
    If (Get-ChildItem $Directory) { Write-Host "$($_.FullName) has files or folders" }
  }
}
 
If ($ADUser.ProfilePath) {
  FindDirectory -Name $DirectoryName -Path $ADUser.ProfilePath
}
If ($ADUser.TsProfilePath) {
  FindDirectory -Name $DirectoryName -Path $ADUser.TsProfilePath
}

Open in new window

0
 
LVL 20

Author Comment

by:strivoli
ID: 24248968
but if one of the profile directory don't exist the script fails:

Get-ChildItem : Cannot find path '\\srvr-file1\winprofiles$\user' because it does not exist

I'd like a write-host for this info and continuing the script
0
 
LVL 20

Author Comment

by:strivoli
ID: 24258423
This is what i made:

now it function well for me!
$DirectoryName = "Documenti"
$ADUser = Get-QADUser "ut01138"
$winprofile = $ADUser.profilepath
$tsprofile = $ADUser.tsprofilepath
 
Function FindDirectory {
  Param($Name, $Path)
 
  Get-ChildItem $Path -Recurse | ?{ $_.Name -eq $Name -And $_.PsIsContainer -eq $True } | %{ 
    Write-Host "$Name è presente in $winprofile" 
    If (Get-ChildItem $Directory) { Write-Host "$($_.FullName) contiene files" }
  }
}
 
If (test-path $ADUser.profilepath) {
  FindDirectory -Name $DirectoryName -Path $ADUser.ProfilePath
}
else
{
$winprofile non c'è su srvr-file1
write-host
}
 
 If (test-path $ADUser.tsprofilepath) {
  FindDirectory -Name $DirectoryName -Path $ADUser.tsProfilePath
}
else
{
$tsprofile non c'è su srvr-file1
write-host
}

Open in new window

0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 240 total points
ID: 24258426

Sorry I missed your previous reply. But Test-Path is exactly what I would have used here :)

Chris
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

850 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