Answered by:
Powershell help - filtering and displaying special output of Get-WMIObject win32_userprofile

Question
-
Is there a way i can filter the outputted data of the following and only display the username?
So..
Get-WMIObject win32_userprofile -filter "special = false" |
Select-Object LocalPathDisplays
c:\Users\charliebrown
when i need it to display
charliebrown
Is this possible with where and can someone please point me in the right direction?
Thursday, February 8, 2018 5:25 PM
Answers
-
Get-WMIObject win32_userprofile -filter "special = false" | Select-Object LocalPath | Foreach { $_.LocalPath.SPlit('\')[2] }
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
- Marked as answer by Ashleyheartspowershell Thursday, February 15, 2018 2:55 PM
Thursday, February 8, 2018 6:02 PM -
$pathnames = 'joe','john','james'$samnames = 'joe','john','roger'$pathnames | foreach { $samnames -eq $_ }
joejohn- Marked as answer by Ashleyheartspowershell Thursday, February 15, 2018 2:55 PM
Thursday, February 8, 2018 6:36 PM -
This seems to work. Copy these two folders (there's a GAC_32 as well). Note that regular users can run some of the commands.
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ActiveDirectory
C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.ActiveDirectory.Management
- Edited by JS2010 Tuesday, February 13, 2018 4:16 PM
- Marked as answer by Ashleyheartspowershell Thursday, February 15, 2018 2:55 PM
Tuesday, February 13, 2018 4:06 PM
All replies
-
Get-WMIObject win32_userprofile -filter "special = false" | Select-Object LocalPath | Foreach { $_.LocalPath.SPlit('\')[2] }
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
- Marked as answer by Ashleyheartspowershell Thursday, February 15, 2018 2:55 PM
Thursday, February 8, 2018 6:02 PM -
Thank you! Now do you know a way to combine that with
Get-ADUser -Filter { Enabled -eq $false } | Select SamAccountName
Basically I want to match and see if a user profile is on the AD disabled list.
Thursday, February 8, 2018 6:20 PM -
$User = Get-WMIObject win32_userprofile -filter "special = false" | Select-Object -ExpandProperty LocalPath | Split-Path -Leaf Get-Aduser -identity $User -properties Enabled
Regards kvprasoon
- Edited by PRASOON KARUNAN V Thursday, February 8, 2018 6:33 PM
Thursday, February 8, 2018 6:32 PM -
$pathnames = 'joe','john','james'$samnames = 'joe','john','roger'$pathnames | foreach { $samnames -eq $_ }
joejohn- Marked as answer by Ashleyheartspowershell Thursday, February 15, 2018 2:55 PM
Thursday, February 8, 2018 6:36 PM -
Get-ADUser : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by parameter 'Identity'. Specified method is not supported. At C:\Users\blah\Desktop\blah.ps1:3 char:22 + Get-Aduser -identity $User -properties Enabled + ~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Thursday, February 8, 2018 6:48 PM -
$user | foreach { Get-Aduser $_ } | where { -not $_.Enabled }I tried to use -filter and crashed and burned.
- Edited by JS2010 Thursday, February 8, 2018 7:41 PM
Thursday, February 8, 2018 6:52 PM -
$User | Foreach-Object -Process { Get-Aduser -identity $_ -properties Enabled }
Regards kvprasoon
Thursday, February 8, 2018 7:11 PM -
Can't use -identity with -filter, can't use -not in -filter:
$user | foreach {
Get-Aduser -filter {Name -eq $_ -and Enabled -eq $False}
}- Edited by JS2010 Friday, February 9, 2018 12:25 AM
Thursday, February 8, 2018 8:03 PM -
I'm confused can you please elaborate on this for me by simply breaking it down?Thursday, February 8, 2018 9:04 PM
-
$user is actually a list of multiple users. So that list gets sent to the foreach loop, and $_ has the value of each user in turn. I'm taking what $user is from PRASOON's code.
- Edited by JS2010 Thursday, February 8, 2018 9:07 PM
Thursday, February 8, 2018 9:06 PM -
Simple,
1. Get the user same using WMI($User = Get-WMIObjectwin32_userprofile -filter "special = false" | Select-Object -ExpandProperty LocalPath | Split-Path -Leaf )
2. Iterate through each user and check that user is Enabled or not in Active Directory
Regards kvprasoon
Friday, February 9, 2018 3:33 AM -
None of the proposed methods will work due to fairly obvious reasons. The only identifier in a user profile is the SID of the associated account.
\_(ツ)_/
Friday, February 9, 2018 4:47 AM -
Are you saying i can't match a disabled user to Get-WMIObject userprofile? I am new to powershell and simply trying to match a way for a user profile to run against the ad user's list to determine if any are disabled. If they are i need it to list and prompt for each user to remove. Is there a better direction you can point me in?Friday, February 9, 2018 2:23 PM
-
If you want to do it with sids:
Get-CimInstance -ClassName Win32_UserProfile -filter "special = false" |select -expand sid |foreach {
Get-Aduser -filter { SID -eq $_ -and Enabled -eq $False }
}- Edited by JS2010 Friday, February 9, 2018 6:55 PM
Friday, February 9, 2018 3:47 PM -
I'm trying this on a machine that does not have RSAT. Is there a way to import the module so I don't have to install it on each machine?Friday, February 9, 2018 7:19 PM
-
Yes, you can do it in two ways.
1. Using Import-PSSession
#Create a session to the DC $Session = New-PSSession -ComputerName <Adserver> #Import the specified module from that session Import-PSSession -Session $Session -Module ActiveDirectory
2. Using Import-Module
#Creates session to ADServer $Session = New-PSSession -ComputerName <AdServer> #Imports ActiveDirectory module using created Session Import-Module -Name ActiveDirectory -PSSesison $Session
We would like you to do below exercise first.
Get-Help Import-PSSession -Full Get-Help Import-Module -Full
Regards kvprasoon
Saturday, February 10, 2018 5:07 AM -
Maybe you can run get-wmiobject or get-ciminstance with the -computername option remotely (or powershell remote)?
- Edited by JS2010 Saturday, February 10, 2018 10:21 PM
Saturday, February 10, 2018 10:02 PM -
This seems to work. Copy these two folders (there's a GAC_32 as well). Note that regular users can run some of the commands.
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ActiveDirectory
C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.ActiveDirectory.Management
- Edited by JS2010 Tuesday, February 13, 2018 4:16 PM
- Marked as answer by Ashleyheartspowershell Thursday, February 15, 2018 2:55 PM
Tuesday, February 13, 2018 4:06 PM