Skip to content

Commit

Permalink
🩹 [Patch]: Enhance documentation for functions (#37)
Browse files Browse the repository at this point in the history
## Description

This pull request includes significant updates to the font management
functions in the PowerShell module, enhancing their functionality and
documentation. The key changes include improved descriptions, added
examples with outputs, and support for additional parameters.

### Enhancements to `Get-Font` function:
* Updated the description to clarify the retrieval of installed fonts
with support for filtering by font name using wildcards.
* Added example outputs to illustrate the function's usage and expected
results.
* Included detailed notes on the returned font object properties and a
link to the function's documentation.

### Enhancements to `Install-Font` function:
* Improved the description to include details on scope, force
installation, and batch installations via pipeline input.
* Added example outputs to demonstrate the function's behavior in
different scenarios, including single file and batch installations.
* Changed the `Scope` parameter type from `Scope[]` to `string` for
better clarity and usage.
* Included notes on the function's outputs and a link to the
documentation.

### Enhancements to `Uninstall-Font` function:
* Updated the description to include support for removing fonts for
either the current user or all users, with administrative privileges
required for the latter.
* Added example outputs to show the verbose logging during font
uninstallation.
* Included notes on the function's behavior and a link to the
documentation.

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] 📖 [Docs]
- [ ] 🪲 [Fix]
- [x] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [ ] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
  • Loading branch information
MariusStorhaug authored Feb 14, 2025
1 parent b746cb0 commit 4c13d1f
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 48 deletions.
62 changes: 51 additions & 11 deletions src/functions/public/Get-Font.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,73 @@
function Get-Font {
<#
.SYNOPSIS
Retrieves the installed fonts.
Retrieves the installed fonts.
.DESCRIPTION
Retrieves the installed fonts.
Retrieves a list of installed fonts for the current user or all users, depending on the specified scope.
Supports filtering by font name using wildcards.
.EXAMPLE
Get-Font
Get-Font
Gets all the fonts installed for the current user.
Output:
```powershell
Name Path Scope
---- ---- -----
Arial C:\Windows\Fonts\arial.ttf CurrentUser
```
Gets all the fonts installed for the current user.
.EXAMPLE
Get-Font -Name 'Arial*'
Get-Font -Name 'Arial*'
Output:
```powershell
Name Path Scope
---- ---- -----
Arial C:\Windows\Fonts\arial.ttf CurrentUser
Arial Bold C:\Windows\Fonts\arialbd.ttf CurrentUser
```
Gets all the fonts installed for the current user that start with 'Arial'.
Gets all the fonts installed for the current user that start with 'Arial'.
.EXAMPLE
Get-Font -Scope 'AllUsers'
Get-Font -Scope 'AllUsers'
Output:
```powershell
Name Path Scope
---- ---- -----
Calibri C:\Windows\Fonts\calibri.ttf AllUsers
```
Gets all the fonts installed for all users.
Gets all the fonts installed for all users.
.EXAMPLE
Get-Font -Name 'Calibri' -Scope 'AllUsers'
Get-Font -Name 'Calibri' -Scope 'AllUsers'
Gets the font with the name 'Calibri' for all users.
Output:
```powershell
Name Path Scope
---- ---- -----
Calibri C:\Windows\Fonts\calibri.ttf AllUsers
```
Gets the font with the name 'Calibri' for all users.
.OUTPUTS
[System.Collections.Generic.List[PSCustomObject]]
System.Collections.Generic.List[PSCustomObject]
.NOTES
Returns a list of installed fonts.
Each font object contains properties:
- Name: The font name.
- Path: The full file path to the font.
- Scope: The scope from which the font is retrieved.
.LINK
https://psmodule.io/Font/Functions/Get-Font
#>
[Alias('Get-Fonts')]
[OutputType([System.Collections.Generic.List[PSCustomObject]])]
Expand Down
103 changes: 76 additions & 27 deletions src/functions/public/Install-Font.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,105 @@
function Install-Font {
<#
.SYNOPSIS
Installs a font in the system
Installs a font in the system.
.DESCRIPTION
Installs a font in the system
Installs a font in the system, either for the current user or all users, depending on the specified scope.
If the font is already installed, it can be optionally overwritten using the `-Force` parameter.
The function supports both single file installations and batch installations via pipeline input.
Installing fonts for all users requires administrator privileges.
.EXAMPLE
Install-Font -Path C:\FontFiles\Arial.ttf
Install-Font -Path C:\FontFiles\Arial.ttf
Output:
```powershell
Arial.ttf installed for the current user.
```
Installs the font file 'C:\FontFiles\Arial.ttf' to the current user profile.
Installs the font file `Arial.ttf` for the current user.
.EXAMPLE
Install-Font -Path C:\FontFiles\Arial.ttf -Scope AllUsers
Install-Font -Path C:\FontFiles\Arial.ttf -Scope AllUsers
Output:
```powershell
Arial.ttf installed for all users.
```
Installs the font file 'C:\FontFiles\Arial.ttf' so it is available for all users.
This requires administrator rights.
Installs the font file `Arial.ttf` system-wide, making it available to all users.
This requires administrator rights.
.EXAMPLE
Install-Font -Path C:\FontFiles\Arial.ttf -Force
Install-Font -Path C:\FontFiles\Arial.ttf -Force
Installs the font file 'C:\FontFiles\Arial.ttf' to the current user profile.
If the font already exists, it will be overwritten.
Output:
```powershell
Arial.ttf reinstalled for the current user.
```
Installs the font file `Arial.ttf` for the current user. If it already exists, it will be overwritten.
.EXAMPLE
Install-Font -Path C:\FontFiles\Arial.ttf -Scope AllUsers -Force
Install-Font -Path C:\FontFiles\Arial.ttf -Scope AllUsers -Force
Output:
```powershell
Arial.ttf reinstalled for all users.
```
Installs the font file 'C:\FontFiles\Arial.ttf' so it is available for all users.
This requires administrator rights. If the font already exists, it will be overwritten.
Installs the font file `Arial.ttf` system-wide and overwrites the existing font if present.
.EXAMPLE
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font
Gets all font files in the folder 'C:\FontFiles\' and installs them to the current user profile.
Output:
```powershell
Found 3 font files.
Arial.ttf installed for the current user.
Verdana.ttf installed for the current user.
TimesNewRoman.ttf installed for the current user.
```
Installs all `.ttf` font files found in `C:\FontFiles\` for the current user.
.EXAMPLE
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font -Scope AllUsers
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font -Scope AllUsers
Output:
```powershell
Found 3 font files.
Arial.ttf installed for all users.
Verdana.ttf installed for all users.
TimesNewRoman.ttf installed for all users.
```
Gets all font files in the folder 'C:\FontFiles\' and installs them so it is available for all users.
This requires administrator rights.
Installs all `.ttf` font files found in `C:\FontFiles\` system-wide.
This requires administrator rights.
.EXAMPLE
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font -Force
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font -Scope AllUsers -Force
Gets all font files in the folder 'C:\FontFiles\' and installs them to the current user profile.
If the font already exists, it will be overwritten.
Output:
```powershell
Found 3 font files.
Arial.ttf reinstalled for all users.
Verdana.ttf reinstalled for all users.
TimesNewRoman.ttf reinstalled for all users.
```
.EXAMPLE
Get-ChildItem -Path C:\FontFiles\ -Filter *.ttf | Install-Font -Scope AllUsers -Force
Installs all `.ttf` font files found in `C:\FontFiles\` system-wide, overwriting existing fonts.
This requires administrator rights.
.OUTPUTS
System.String
.NOTES
Returns messages indicating success or failure of font installation.
Gets all font files in the folder 'C:\FontFiles\' and installs them so it is available for all users.
This requires administrator rights. If the font already exists, it will be overwritten.
.LINK
https://psmodule.io/Admin/Functions/Install-Font/
#>
[Alias('Install-Fonts')]
[CmdletBinding(SupportsShouldProcess)]
Expand All @@ -70,13 +119,13 @@ function Install-Font {
# CurrentUser will install the font for the current user only.
# AllUsers will install the font so it is available for all users on the system.
[Parameter(ValueFromPipelineByPropertyName)]
[Scope[]] $Scope = 'CurrentUser',
[string] $Scope = 'CurrentUser',

# Recurse will install all fonts in the specified folder and subfolders.
[Parameter()]
[switch] $Recurse,

# Force will overwrite existing fonts
# Force will overwrite existing fonts.
[Parameter()]
[switch] $Force
)
Expand Down
42 changes: 32 additions & 10 deletions src/functions/public/Uninstall-Font.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
#Requires -Modules @{ ModuleName = 'Admin'; RequiredVersion = '1.1.3' }

function Uninstall-Font {
function Uninstall-Font {
<#
.SYNOPSIS
Uninstalls a font from the system.
Uninstalls a font from the system.
.DESCRIPTION
Uninstalls a font from the system.
Uninstalls a font from the system. The function supports removing fonts for either the current user
or all users. If attempting to remove a font for all users, administrative privileges are required.
The function ensures font files are deleted, and if on Windows, it also unregisters fonts from the registry.
.EXAMPLE
Uninstall-Font -Name 'Courier New'
Uninstall-Font -Name 'Courier New'
Output:
```powershell
VERBOSE: [Uninstall-Font] - [CurrentUser] - [Courier New] - Processing
VERBOSE: [Uninstall-Font] - [CurrentUser] - [Courier New] - Removing file [C:\Windows\Fonts\cour.ttf]
VERBOSE: [Uninstall-Font] - [CurrentUser] - [Courier New] - Unregistering font [Courier New]
VERBOSE: [Uninstall-Font] - [CurrentUser] - [Courier New] - Done
```
Uninstalls the 'Courier New' font from the system for the current user.
Uninstalls the 'Courier New' font from the system for the current user.
.EXAMPLE
Uninstall-Font -Name 'Courier New' -Scope AllUsers
Uninstall-Font -Name 'Courier New' -Scope AllUsers
Output:
```powershell
VERBOSE: [Uninstall-Font] - [AllUsers] - [Courier New] - Processing
VERBOSE: [Uninstall-Font] - [AllUsers] - [Courier New] - Removing file [C:\Windows\Fonts\cour.ttf]
VERBOSE: [Uninstall-Font] - [AllUsers] - [Courier New] - Unregistering font [Courier New]
VERBOSE: [Uninstall-Font] - [AllUsers] - [Courier New] - Done
```
Uninstalls the Courier New font from the system for all users.
Uninstalls the 'Courier New' font from the system for all users. Requires administrative privileges.
.OUTPUTS
None
None
.NOTES
The function does not return any objects.
.LINK
https://psmodule.io/Admin/Functions/Uninstall-Font/
#>
[Alias('Uninstall-Fonts')]
[CmdletBinding()]
Expand Down

0 comments on commit 4c13d1f

Please sign in to comment.