1818. PARAMETER OutDirectory
1919 The directory where the HTML file will be saved. If not specified, uses the current directory.
2020
21+ . PARAMETER PassThru
22+ If specified, the function will return the post object instead of just saving it to a file
23+
2124. EXAMPLE
22- Get-BloggerPost -PostId "1234567890123456789"
25+ # obtain a post from the blog defined in the user preferences
26+ $post = Get-BloggerPost -PostId "1234567890123456789"
2327
2428. EXAMPLE
29+ # obtain a post from a specified blog and save it as HTML in a specific directory
2530 Get-BloggerPost -BlogId "9876543210987654321" -PostId "1234567890123456789" -Format HTML -OutDirectory "C:\temp"
2631
2732. EXAMPLE
33+ # obtain a post from a specified blog and save it as Markdown in a specific directory with a date-based folder structure
2834 Get-BloggerPost -BlogId "9876543210987654321" -PostId "1234567890123456789" -Format Markdown -DateFormat "YYYY\\MM" -OutDirectory "C:\blogposts"
35+
36+ . EXAMPLE
37+ # obtain a post from a specified blog and save it as JSON in the current directory
38+ Get-BloggerPost -BlogId "9876543210987654321" -PostId "1234567890123456789" -Format JSON
39+
40+ . EXAMPLE
41+ # obtain a post from a specified blog, write it to disk and return the post object
42+ $post = Get-BloggerPost -BlogId "9876543210987654321" -PostId "1234567890123456789" -Format Markdown -PassThru
2943#>
3044Function Get-BloggerPost {
3145 [CmdletBinding ()]
@@ -46,7 +60,10 @@ Function Get-BloggerPost {
4660 [string ]$FolderDateFormat ,
4761
4862 [Parameter (ParameterSetName = " Persist" )]
49- [string ]$OutDirectory = (Get-Location ).Path
63+ [string ]$OutDirectory = (Get-Location ).Path,
64+
65+ [Parameter (ParameterSetName = " Persist" )]
66+ [switch ]$PassThru
5067 )
5168
5269 if (! $PSBoundParameters.ContainsKey (" BlogId" )) {
@@ -56,10 +73,6 @@ Function Get-BloggerPost {
5673 }
5774 }
5875
59- if ([string ]::IsNullOrEmpty($PostId )) {
60- throw " PostId is required."
61- }
62-
6376 try {
6477 $uri = " https://www.googleapis.com/blogger/v3/blogs/$BlogId /posts/$PostId "
6578
@@ -130,7 +143,7 @@ Function Get-BloggerPost {
130143 $file = " $title .md"
131144
132145 $filePath = Join-Path - Path $OutDirectory - ChildPath $file
133- ConvertTo-MarkdownFromHtml - Content $result.content - OutFile $filePath > $null
146+ ConvertTo-MarkdownFromHtml - Content $result.content - OutFile $filePath
134147 Set-MarkdownFrontMatter - File $filePath -Replace $frontMatter
135148 Write-Verbose " Post content saved to: $filePath "
136149 }
@@ -144,7 +157,10 @@ Function Get-BloggerPost {
144157 }
145158
146159 # Return the post object for further processing if needed
147- return $result
160+ if (! ($PSCmdlet.ParameterSetName -eq " Persist" ) -or ($PassThru.IsPresent -and $PassThru )) {
161+ Write-Verbose " Returning blog post object"
162+ return $result
163+ }
148164 }
149165 catch {
150166 throw " Failed to save post content: $ ( $_.Exception.Message ) "
0 commit comments