-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-CMUserPrimaryDevice.ps1
47 lines (41 loc) · 1.34 KB
/
Get-CMUserPrimaryDevice.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Get-CMUserPrimaryDevice {
<#
.SYNOPSIS
Gets a user's primary device from SCCM database
.DESCRIPTION
Connects to SCCM and obtains a users primary device from the SMS database
.PARAMETER identity
This requires sAMAccountName in order to successfully find the user in SMS database.
.EXAMPLE
Get-CMUserPrimaryDevice -Identity Brett.Miller
.EXAMPLE
'Brett.Miller' | Get-CMUserPrimaryDevice
.Example
Get-aduser brett.miller | select -ExpandProperty samaccountname | Get-CMUserPrimaryDevice
#>
[CmdletBinding(PositionalBinding=$false)]
param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[string[]]$identity
)
process {
foreach ($person in $identity) {
$userobj = Get-CMUserDeviceAffinity -UserName ("fqdn\{0}" -f $person)
if ($userobj){
[PSCustomObject]@{
sAMAccountName = ($userobj.uniqueusername | Select-Object -First 1).substring(5)
ComputerName = $userobj | Select-Object -ExpandProperty resourcename
}
}
else {
[PSCustomObject]@{
sAMAccountName = $person
ComputerName = $null
}
}
}
}
}