This isn't the fastest (using .NET would be), but it's easy to understand:
$username = ( gwmi win32_computersystem ).username.ToString()
$sid = ( gwmi win32_useraccount |? { $_.Caption -eq $username } ).SID
gwmi win32_userprofile |? { $_.SID -eq $sid }
From: [email protected] [mailto:[email protected]] On
Behalf Of James Rankin
Sent: Thursday, October 12, 2017 3:45 PM
To: [email protected]
Subject: [NTSysADM] PowerShell brainfart
OK, I'm having a ditzy moment
I'm trying to query profile type in PowerShell using gwmi
Specifically gwmi win32_userprofile | select localpath, status
But this returns all users on the machine - how can I make it return just the
current user? I'm having a severe blonde moment - help!
(Apologies to all blondes on the list)
Cheers,
[cid:[email protected]]
[cid:[email protected]]
[cid:[email protected]]
James Rankin CTA ACA vExpert
Technical Evangelist / Media Hound
Howell Technology Group
Office: 0191 4813446
Mobile: 07809 668579
Email: [email protected]<mailto:[email protected]>
www.htguk.com<http://www.htguk.com/> | Twitter<https://twitter.com/htguk> |
Linkedin<https://www.linkedin.com/in/markhtg> |
Facebook<https://www.facebook.com/HTGUK>
COMPANY INFORMATION
Howell Technology Group Ltd is a limited company registered in England with
registered number 5520670 and VAT registered number GB 862 666 004. Our
registered office is at 2.30 One Trinity Green, Eldon Street, South Shields,
Tyne & Wear, NE33 1SA
CONFIDENTIALITY NOTICE
This message is intended solely for the addressee and may contain confidential
information. If you have received this message in error, please send it back to
us, and immediately and permanently delete it. Do not use, copy or disclose the
information contained in this message or in any attachment.
PRIVACY POLICY
For information about how we process data and monitor communications please see
our Privacy Policy.
To log a ticket please follow the link. https://htguk.on.spiceworks.com/portal