-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-MyProfile.ps1
56 lines (45 loc) · 2.23 KB
/
Get-MyProfile.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
56
function Get-MyProfile {
<#
.SYNOPSIS
Shows all profile files.
.DESCRIPTION
The four potential file locations for the profile are returned, together with an extra property for the files that really exist.
The $PROFILE variable holds 4 filepaths, depending on the current user and the current host. That does not mean those files all exist.
This function returns not only the provided paths, but also whether they really exist.
.PARAMETER Edit
When this switch is added, the existing profile files are opened with notepad.
.EXAMPLE
Get-MyProfile -Edit
Shows what locations are provided for the four profile files for the current context, and the actual files for those that exist.
The existing files are opened with notepad.
.NOTES
Author: Klaas Vandenberghe
Date: 2017-03-09
.INPUTS
None
.OUTPUTS
PSCustomObject
Files
#>
[CmdletBinding()]
Param (
[Switch]$Edit
)
if ($PSBoundParameters.ContainsKey('Edit'))
{
if ( Test-Path -Path $profile.AllUsersAllHosts ) { & "$env:windir\system32\notepad.exe" $profile.AllUsersAllHosts }
if ( Test-Path -Path $profile.AllUsersCurrentHost ) { & "$env:windir\system32\notepad.exe" $profile.AllUsersCurrentHost }
if ( Test-Path -Path $profile.CurrentUserAllHosts ) { & "$env:windir\system32\notepad.exe" $profile.CurrentUserAllHosts }
if ( Test-Path -Path $profile.CurrentUserCurrentHost ) { & "$env:windir\system32\notepad.exe" $profile.CurrentUserCurrentHost }
}
[PSCustomObject]@{
AllUsersAllHosts = $profile.AllUsersAllHosts
AllUsersCurrentHost = $profile.AllUsersCurrentHost
CurrentUserAllHosts = $profile.CurrentUserAllHosts
CurrentUserCurrentHost = $profile.CurrentUserCurrentHost
AllUsersAllHostsFile = $(if ( Test-Path -Path $profile.AllUsersAllHosts ) { $profile.AllUsersAllHosts })
AllUsersCurrentHostFile = $(if ( Test-Path -Path $profile.AllUsersCurrentHost ) { $profile.AllUsersCurrentHost })
CurrentUserAllHostsFile = $(if ( Test-Path -Path $profile.CurrentUserAllHosts ) { $profile.CurrentUserAllHosts})
CurrentUserCurrentHostFile = $(if ( Test-Path -Path $profile.CurrentUserCurrentHost ) { $profile.CurrentUserCurrentHost})
}
}