PoshCode Archive  Artifact [c41f27989a]

Artifact c41f27989a334625aa71ce105950a7648e4300c71038f46a931eec1bb2c865ce:

  • File Get-UserProfileList.ps1 — part of check-in [60ec0f8fe4] at 2018-06-10 14:04:48 on branch trunk — Used to get a list of User Profiles from a Target PC. (user: Chris Rakowitz size: 2196)

# encoding: ascii
# api: powershell
# title: Get-UserProfileList
# description: Used to get a list of User Profiles from a Target PC.
# version: 0.1
# type: class
# author: Chris Rakowitz
# license: CC0
# x-poshcode-id: 5954
# x-archived: 2015-08-02T00:52:19
# x-published: 2015-07-30T17:13:00
#
#
#  /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\  
# /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \ 
#/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \
#|----
#|----@Author:  Chris Rakowitz
#|----@Purpose: Returns a list of User Profiles from a Target Machine.
#|----				Pressing Enter without entering a PC Name or IP will
#|----				generate the information for the local machine.
#|----            Usage:  .\Single-GetUserList.ps1 <PCNAME or IP>
#|----@Date: April 15, 2015
#|----@Version: 1
#|----
#\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /\    /
# \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  /  \  / 
#  \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/    \/  

[cmdletbinding()]
param
(
	[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
	$ComputerName = $env:computername
)        
$ErrorActionPreference = 'silentlycontinue'	#Skip all the annoying Error Messages

# For each Profile on the PC, extract information
$Profiles = Get-WmiObject -Class Win32_UserProfile -Computer $ComputerName -ea 0
foreach ($Profile in $Profiles)
{
	# Skip NetworkService, LocalService and SystemProfile. No need to process.
	if($Profile.localpath -like 'C:\Windows\*') 
	{
		continue
	}
	else
	{
		$objSID = New-Object System.Security.Principal.SecurityIdentifier($Profile.sid)
		$objuser = $objSID.Translate([System.Security.Principal.NTAccount])

		$OutputObj = New-Object -TypeName PSobject
		$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.toUpper()
		$OutputObj | Add-Member -MemberType NoteProperty -Name ProfileName -Value $objuser.value
		$OutputObj | Add-Member -MemberType NoteProperty -Name ProfilePath -Value $Profile.localpath
		
		$OutputObj
	}
}