Skip to content

Commit 57e0d1b

Browse files
Merge pull request #18 from PowershellFrameworkCollective/scopes
docs updates for 1.13.406
2 parents 64792cd + 0b706c0 commit 57e0d1b

5 files changed

Lines changed: 110 additions & 72 deletions

File tree

documentation/documents/psframework/logging/loggingto/logfile.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ Set-PSFLoggingProvider @paramSetPSFLoggingProvider
5454

5555
This will delete all logs older than 30 days.
5656

57+
> Plaintext Logs
58+
59+
Want a classic plaintext log?
60+
Well, generally we do not recommend using those (as they are hard to process automatically, compared to structured data logs), but sometimes you just need something for a quick peek in notepad and a plain text logfile is just easy to read for the human eye.
61+
62+
Worry not, we have you covered:
63+
64+
```powershell
65+
$paramSetPSFLoggingProvider = @{
66+
Name = 'logfile'
67+
InstanceName = '<taskname>'
68+
FilePath = 'C:\Logs\TaskName-%Date%.txt'
69+
FileType = 'TXT'
70+
Enabled = $true
71+
Wait = $true
72+
}
73+
Set-PSFLoggingProvider @paramSetPSFLoggingProvider
74+
```
75+
5776
## Generating Messages
5877

5978
You can write messages using the `Write-PSFMessage` cmdlet, which functionally replaces Write-Verbose, Write-Host, Write-Warning, Write-Debug or Write-Log:

documentation/documents/psframework/logging/providers/logfile.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It also offers logrotate capabilities, to clean up after itself.
3030
|---|---|---|
3131
|CsvDelimiter|,|The delimiter to use when writing to csv.|
3232
|FilePath||The path to where the logfile is written. Supports some placeholders such as %Date% to allow for timestamp in the name.|
33-
|FileType|CSV|In what format to write the logfile. Supported styles: CSV, XML, Html, Json or CMTrace. Html, XML and Json will be written as fragments.|
33+
|FileType|CSV|In what format to write the logfile. Supported styles: CSV, XML, Html, Json, TXT or CMTrace. Html, XML and Json will be written as fragments.|
3434
|Headers|'ComputerName', 'File', 'FunctionName', 'Level', 'Line', 'Message', 'ModuleName', 'Runspace', 'Tags', 'TargetObject', 'Timestamp', 'Type', 'Username'|The properties to export, in the order to select them. For writing the data field or renaming properties, see below under "Notes".|
3535
|IncludeHeader|True|Whether a written csv file will include headers|
3636
|Logname||A special string you can use as a placeholder in the logfile path (by using '%logname%' as placeholder)|
@@ -45,6 +45,11 @@ It also offers logrotate capabilities, to clean up after itself.
4545
|JsonCompress|$false|Will compress the json entries, condensing each entry into a single line.|
4646
|JsonString|$false|Will convert all enumerated properties to string values when converting to json. This causes the level property to be 'Debug','Host', ... rather than 8,2,...|
4747
|JsonNoComma|$false|Prevent adding commas between two json entries.|
48+
|JsonNoEmptyFirstLine|$false|Prevent the empty first line when commas have not been disabled.|
49+
|CMTraceOverrideComponent|$false|When Enabled, messages that include a "Data" hashtable with a "Component" entry will use that Entry for the log message Component element, rather than the auto-calculated one.|
50+
|TXTPattern|'%Timestamp% [%Level%] %Message%'|The pattern of any given line in the TXT-based logfile. Use %PROPERTYNAME% as placeholder, e.g. "%Message%". Same properties as with the headers configuration - you need to specify both settings, if your pattern includes non-default properties such as "Data".|
51+
|MoveOnFinal|''|Path to a target folder to move logfiles to when shutting down the logging provider instance. This happens automatically when PSFramework ends or the provider instance is disabled again.|
52+
|CopyOnFinal|''|Path to a target folder to copy logfiles to when shutting down the logging provider instance. This happens automatically when PSFramework ends or the provider instance is disabled again.|
4853

4954
## Notes
5055

@@ -57,6 +62,7 @@ The default format is CSV, but there is more ...
5762
|---|---|
5863
|CSV|The default format. A common CSV and the only type that respects the CsvDelimiter setting. Easy to open in Excel, making it a popular format for admins. However, as it is a flat table, this format cannot support the Data field.|
5964
|Json|Writes entries as Json string. However, as each individual write cannot guarantee it being the last to write an entry to the file, all entries are written as _fragments_ . To turn the resulting file content into valid json, wrap it into square brackets.|
65+
|TXT|Writes a plaintext logfile. Generally not recommended, as logs in structured data formats are easier to automatically process, parse and monitor. Use the `TXTPattern` setting to define just how the log looks, all properties selected must also be included in the `Headers` setting.|
6066
|XML|Writes entries as XML string. However, as each individual write cannot guarantee it being the last to write an entry to the file, all entries are written as _fragments_ . To turn the resulting file content into valid XML, wrap it into a `<Messages>` XML element.|
6167
|Html|Writes entries as Html string. However, as each individual write cannot guarantee it being the last to write an entry to the file, all entries are written as _fragments_ . To turn the resulting file content into valid html, wrap it into a `<table>` html element.|
6268
|CMTrace|Writes log entries in a format that can easily be consumed by the CMTrace log reading utility part of SCCM. This type ignores the selected headers to write and cannot support the Data field.|

documentation/documents/psframework/logging/providers/sql.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Or manually deploy the required module.
4242
|Table|LoggingTable|Name of the table in that database to write to. Will be created if needed and able.|
4343
|SqlServer||The SQL Server to connect to.|
4444
|Credential||The credentials to use for connecting to the SQL server.|
45+
|Schema|dbo|SQL Server schema.|
46+
|Headers|'Message', 'Timestamp', 'Level', 'Tags', 'Data', 'ComputerName', 'Runspace', 'UserName', 'ModuleName', 'FunctionName', 'File', 'Line', 'CallStack', 'TargetObject', 'ErrorRecord'|Columns to write to the table|
4547

4648
## Notes
4749

documentation/documents/psframework/parameter-classes/path-parameter.md

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ Example:
1515

1616
```powershell
1717
function Get-FileContent {
18-
[CmdletBinding()]
19-
param (
20-
[string[]]
21-
$Path
22-
)
23-
24-
foreach ($entry in $Path) {
25-
try { $resolvedPaths = Resolve-Path -Path $entry -ErrorAction Stop }
26-
catch {
27-
Write-Error $_
28-
continue
29-
}
30-
31-
foreach ($resolvedPath in $resolvedPaths) {
32-
if (-not (Test-Path -Path $resolvedPath -PathType Leaf)) {
33-
Write-Warning "Not a file: $resolvedPath"
34-
continue
35-
}
36-
37-
# Do Something
38-
}
39-
}
18+
[CmdletBinding()]
19+
param (
20+
[string[]]
21+
$Path
22+
)
23+
24+
foreach ($entry in $Path) {
25+
try { $resolvedPaths = Resolve-Path -Path $entry -ErrorAction Stop }
26+
catch {
27+
Write-Error $_
28+
continue
29+
}
30+
31+
foreach ($resolvedPath in $resolvedPaths) {
32+
if (-not (Test-Path -Path $resolvedPath -PathType Leaf)) {
33+
Write-Warning "Not a file: $resolvedPath"
34+
continue
35+
}
36+
37+
# Do Something
38+
}
39+
}
4040
}
4141
```
4242

@@ -45,34 +45,34 @@ with this parameter class, the same code however can be condensed to ...
4545

4646
```powershell
4747
function Get-FileContent {
48-
[CmdletBinding()]
49-
param (
50-
[PsfFile]
51-
$Path
52-
)
53-
54-
foreach ($filePath in $Path) {
55-
# Do Something
56-
}
48+
[CmdletBinding()]
49+
param (
50+
[PsfFile]
51+
$Path
52+
)
53+
54+
foreach ($filePath in $Path) {
55+
# Do Something
56+
}
5757
}
5858
```
5959

6060
Adding support for `-LiteralPath` is no harder:
6161

6262
```powershell
6363
function Get-FileContent {
64-
[CmdletBinding()]
65-
param (
66-
[PsfFile]
67-
$Path,
68-
69-
[PsfLiteralPath]
70-
$LiteralPath
71-
)
72-
73-
foreach ($filePath in $Path + $LiteralPath) {
74-
# Do Something
75-
}
64+
[CmdletBinding()]
65+
param (
66+
[PsfFile]
67+
$Path,
68+
69+
[PsfLiteralPath]
70+
$LiteralPath
71+
)
72+
73+
foreach ($filePath in $Path + $LiteralPath) {
74+
# Do Something
75+
}
7676
}
7777
```
7878

@@ -82,21 +82,21 @@ Sometimes we need to provide a path to a file that does not yet exist - for exam
8282
In that case, the folder should already exist, but the file usually would not.
8383
In the previous example however, we require the file to already exist!
8484

85-
For this scenario, there exists the `[PsfNewFile]` parameter class, which allows for a file to not yet exist, so long as the parent folder does:
85+
For this scenario, there exists the `[PsfNewFileSingle]` parameter class, which allows for a file to not yet exist, so long as the parent folder does:
8686

8787
```powershell
8888
function Export-SystemReport {
89-
[CmdletBinding()]
90-
param (
91-
[Parameter(Mandatory = $true)]
92-
[PsfNewFile]
93-
$OutPath
94-
)
89+
[CmdletBinding()]
90+
param (
91+
[Parameter(Mandatory = $true)]
92+
[PsfNewFileSingle]
93+
$OutPath
94+
)
9595
96-
# Do Something
97-
# ...
96+
# Do Something
97+
# ...
9898
99-
$results | Export-PSFClixml -Path $OutPath
99+
$results | Export-PSFClixml -Path $OutPath
100100
}
101101
```
102102

@@ -112,34 +112,41 @@ Instead, this variant will have a `FailedInput` property, listing all the input
112112

113113
```powershell
114114
function Get-FileContent {
115-
[CmdletBinding()]
116-
param (
117-
[PsfFileLax]
118-
$Path
119-
)
120-
121-
foreach ($entry in $Path.FailedInput) {
122-
Write-Warning "Could not resolve as file: $entry"
123-
}
124-
125-
foreach ($filePath in $Path) {
126-
# Do Something
127-
}
115+
[CmdletBinding()]
116+
param (
117+
[PsfFileLax]
118+
$Path
119+
)
120+
121+
foreach ($entry in $Path.FailedInput) {
122+
Write-Warning "Could not resolve as file: $entry"
123+
}
124+
125+
foreach ($filePath in $Path) {
126+
# Do Something
127+
}
128128
}
129129
```
130130

131131
## The different types
132132

133-
There are 9 different parameter classes that fall under this category:
133+
There are 16 different parameter classes that fall under this category:
134134

135135
+ PsfPath: Path to folders or files
136136
+ PsfPathLax: Path to folders or files, will not generate errors on bad input
137+
+ PsfPathSingle: Path to a single folder or file
137138
+ PsfNewFile: Path to a file where at least the folder exists
139+
+ PsfNewFileSingle: Path to a single file where at least the folder exists
138140
+ PsfFile: Path to files that exist
139141
+ PsfFileLax: Path to files that exist, will not generate errors on bad input
142+
+ PsfFileSingle: Path to a single file that exists
140143
+ PsfDirectory: Path to folders that exist
141144
+ PsfDirectoryLax: Path to folders that exist, will not generate errors on bad input
145+
+ PsfDirectorySingle: Path to a single folder that exists
142146
+ PsfLiteralpath: Path to folders or files, will not use wildcard interpretation.
143147
+ PsfLiteralpathLax: Path to folders or files, will not use wildcard interpretation. Will not generate errors on bad input
148+
+ PsfLiteralpathSingle: Path to a single folder or file, will not use wildcard interpretation.
149+
+ PsfLiteralFileSingle: Path to a single file, will not use wildcard interpretation.
150+
+ PsfLiteralDirectorySingle: Path to a single folder, will not use wildcard interpretation.
144151

145152
[Back to Parameter Classes](https://psframework.org/documentation/documents/psframework/parameter-classes.html)

documentation/quickstart/psframework.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ In many cases, we build helping infrastructure for our modules in as minimal a w
55
The PSFramework fills that gap, whether it is powerful and flexible logging, configuration management, tab completion or runspace management.
66
Its functionalities are split into many separate groups, these are quick start guides that are supposed to give you an easy entry into their respective group:
77

8-
- Configuration: [Getting Started with Configuration](psframework/configuration.html)
9-
- Logging: [Getting Started with Logging](psframework/logging.html)
10-
- Parameter Classes: [Getting Started with Parameter Classes](psframework/parameter-classes.html)
11-
- Tab Completion: [Getting Started with Tab Completion](psframework/tabcompletion.html)
8+
- Configuration: [Getting Started with Configuration](psframework/configuration.html)
9+
- Logging: [Getting Started with Logging](psframework/logging.html)
10+
- Parameter Classes: [Getting Started with Parameter Classes](psframework/parameter-classes.html)
11+
- Tab Completion: [Getting Started with Tab Completion](psframework/tabcompletion.html)
12+
13+
> Conference Recording
14+
15+
At PSConfEU 2024, Fred gave a talk on [Quick Wins with the PSFramework](https://www.youtube.com/watch?v=xD3Hh-jNOg4), which should also serve well in getting ... well quick wins / gains and accelerate adoption.

0 commit comments

Comments
 (0)