-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-OneShellUserProfileSystem.ps1
56 lines (53 loc) · 2.36 KB
/
Get-OneShellUserProfileSystem.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
48
49
50
51
52
53
54
55
Function Get-OneShellUserProfileSystem
{
[cmdletbinding(DefaultParameterSetName = 'All')]
param
(
[parameter(ValueFromPipelineByPropertyName)]
[string]$ProfileIdentity
,
[parameter(ParameterSetName = 'Identity', ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]]$Identity
,
[parameter(ValueFromPipelineByPropertyName)]
[string]$ServiceType
,
[parameter()]
[ValidateScript( {Test-DirectoryPath -Path $_})]
[string[]]$Path = $Script:OneShellUserProfilePath
,
[parameter()]
[ValidateScript( {Test-DirectoryPath -Path $_})]
[string[]]$OrgProfilePath = $Script:OneShellOrgProfilePath
)#end param
Process
{
$UserProfiles = @(
$GetUserProfileParams = @{
ErrorAction = 'Stop'
Path = $Path
}
if (Test-IsNotNullOrWhiteSpace -String $ProfileIdentity)
{
$GetUserProfileParams.Identity = $ProfileIdentity
}
Get-OneShellUserProfile @GetUserProfileParams
)#end UserProfiles
Write-Verbose -Message "Got $($UserProfiles.count) User Profiles"
$OutputSystems = @(
foreach ($up in $UserProfiles)
{
$orgProfile = Get-OneShellOrgProfile -Identity $up.organization.Identity -ErrorAction Stop -Path $OrgProfilePath
foreach ($us in $up.systems)
{
$os = $orgProfile.systems | Where-Object -FilterScript {$_.Identity -eq $us.identity}
$us | Select-Object -Property *, @{n = 'ServiceType'; e = {$os.ServiceType}}, @{n = 'Name'; e = {$os.name}}, @{n = 'ProfileName'; e = {$up.Name}}, @{n = 'ProfileIdentity'; e = {$up.Identity}}, @{n = 'OrgName'; e = {$orgProfile.Name}}, @{n = 'OrgIdentity'; e = {$orgProfile.Identity}}
}
}
)
#filter based on Identity and Service Type
$OutputSystems = @($OutputSystems | Where-Object -FilterScript {$_.ServiceType -in $ServiceType -or (Test-IsNullorWhiteSpace -String $ServiceType)})
$OutputSystems = @($OutputSystems | Where-Object -FilterScript {$_.Identity -in $Identity -or $_.Name -in $Identity -or (Test-IsNullorWhiteSpace -String $Identity)})
$OutputSystems
}#end Process
}