Powershell - Pull date modified for profiles in C:\users

Hi EE

Anyone have a PS script or utility that I can use to pull the Date modified for all profiles in C:\Users for multiple servers ?
LVL 2
MilesLoganAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steven HarrisPresidentCommented:
You can use PowerShell with something like:

$wmi = [WMI] ""
$results = get-wmiobject Win32_UserProfile | foreach-object {
  $userAccount = [WMI] ("root/cimv2:Win32_SID.SID='{0}'" -f $_.SID)
  $userName = "{0}\{1}" -f $userAccount.ReferencedDomainName,$userAccount.AccountName
  new-object PSObject -property @{
    "Name" = $userName
    "LastUseTime" = $wmi.ConvertToDatetime($_.LastUseTime)
  }
}
$results | export-csv mycsv.csv -notypeinformation

Open in new window

0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Of course that will only work locally. To apply it to a list of servers (and have improved output), you would need something like:
Get-WmiObject -ComputerName (get-content c:\Servers.txt) Win32_UserProfile | % {
  $userinfo = [WMI] ($_.__Path -Replace "Win32_UserProfile", "Win32_SID")
  New-Object PsObject -Property @{
    ComputerName= $_.__Server
    Domain      = $userinfo.ReferencedDomainName
    User        = $userinfo.AccountName
    LastUsed    = $_.ConvertToDatetime($_.LastUseTime)
  }
}

Open in new window

0
MilesLoganAuthor Commented:
Thank you both, I was able to get output from  ThinkSpaceSolutions for the local machine but I do need it for multiple machines so I was needing something like Qlemo's example ..

Qlemo please see the error below.


Get-WmiObject : Invalid class "Win32_UserProfile"
At C:\test\Qlemo_test.ps1:1 char:1
+ Get-WmiObject -ComputerName (get-content c:\test\Servers.txt) Win32_UserProfile  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Win32_UserProfile only to works with Vista/2008 and above.
0
MilesLoganAuthor Commented:
my bad .. I was testing it to pull data from an XP machine .. worked great for 2003/2008 server.. thanks ! can you help me export it to a CSV file ?
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
No issue at all. Just append the export-csv cmdlet to the pipe:
Get-WmiObject -ComputerName (get-content c:\Servers.txt) Win32_UserProfile | % {
  $userinfo = [WMI] ($_.__Path -Replace "Win32_UserProfile", "Win32_SID")
  New-Object PsObject -Property @{
    ComputerName= $_.__Server
    Domain      = $userinfo.ReferencedDomainName
    User        = $userinfo.AccountName
    LastUsed    = $_.ConvertToDatetime($_.LastUseTime)
  }
} | export-csv -NoType c:\Results.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MilesLoganAuthor Commented:
| export-csv -NoType c:\Results.csv  lol .. I was close !

thank you so much !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.