PowerShell/Docs/list-profiles.md

59 lines
2.0 KiB
Markdown
Raw Normal View History

2022-12-04 10:40:18 +01:00
## The *list-profiles.ps1* Script
2022-11-17 20:02:26 +01:00
list-profiles.ps1
2021-10-17 14:33:27 +02:00
## Parameters
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2022-11-17 20:02:26 +01:00
## Source Code
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
Lists the user's PowerShell profiles
.DESCRIPTION
This PowerShell script lists the user's PowerShell profiles.
.EXAMPLE
PS> ./list-profiles
Level Profile Location Existent
----- ------- -------- --------
1 AllUsersAllHosts /opt/PowerShell/profile.ps1 no
2 AllUsersCurrentHost /opt/PowerShell/Microsoft.PowerShell_profile.ps1 no
3 CurrentUserAllHosts /home/markus/.config/powershell/profile.ps1 no
4 CurrentUserCurrentHost /home/markus/.config/powershell/Microsoft.PowerShell_profile.ps1 yes
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function ListProfile { param([int]$Level, [string]$Profile, [string]$Location)
if (test-path "$Location") { $Existent = "yes" } else { $Existent = "no" }
New-Object PSObject -Property @{ 'Level'="$Level"; 'Profile'="$Profile"; 'Location'="$Location"; 'Existent'="$Existent" }
}
function ListProfiles {
ListProfile 1 "AllUsersAllHosts" $PROFILE.AllUsersAllHosts
ListProfile 2 "AllUsersCurrentHost" $PROFILE.AllUsersCurrentHost
ListProfile 3 "CurrentUserAllHosts" $PROFILE.CurrentUserAllHosts
ListProfile 4 "CurrentUserCurrentHost" $PROFILE.CurrentUserCurrentHost
}
try {
ListProfiles | format-table -property Level,Profile,Location,Existent
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2021-10-17 14:33:27 +02:00
*Generated by convert-ps2md.ps1 using the comment-based help of list-profiles.ps1*