-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function New-GSDocument { | ||
<# | ||
.SYNOPSIS | ||
Creates a new Document | ||
.DESCRIPTION | ||
Creates a new Document | ||
.PARAMETER Title | ||
The name of the new Document | ||
.PARAMETER User | ||
The user to create the Document for | ||
.PARAMETER Launch | ||
If $true, opens the new Document Url in your default browser | ||
.EXAMPLE | ||
New-GSDocument -Title "Finance Document" -Launch | ||
Creates a new Document titled "Finance Document" and opens it in the browser on creation | ||
#> | ||
[OutputType('Google.Apis.Docs.v1.Data.Document')] | ||
[cmdletbinding()] | ||
Param | ||
( | ||
[parameter(Mandatory = $false,ValueFromPipeline = $true,Position = 0)] | ||
[String] | ||
$Title = "Untitled document", | ||
[parameter(Mandatory = $false)] | ||
[Alias('Owner','PrimaryEmail','UserKey','Mail')] | ||
[string] | ||
$User = $Script:PSGSuite.AdminEmail, | ||
[parameter(Mandatory = $false)] | ||
[Alias('Open')] | ||
[Switch] | ||
$Launch | ||
) | ||
Begin { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/drive' | ||
ServiceType = 'Google.Apis.Docs.v1.DocsService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
} | ||
Process { | ||
try { | ||
$body = New-Object 'Google.Apis.Docs.v1.Data.Document' | ||
$body.Title = $Title | ||
Write-Verbose "Creating Document '$Title' for user '$User'" | ||
$request = $service.Documents.Create($body) | ||
$response = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
if ($Launch) { | ||
$DocumentUrl = (Get-GSDriveFile $response.DocumentId).WebViewLink | ||
Write-Verbose "Launching new document at $DocumentUrl" | ||
Start-Process $DocumentUrl | ||
} | ||
$response | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function New-GSPresentation { | ||
<# | ||
.SYNOPSIS | ||
Creates a new Presentation | ||
.DESCRIPTION | ||
Creates a new Presentation | ||
.PARAMETER Title | ||
The name of the new Presentation | ||
.PARAMETER User | ||
The user to create the Presentation for | ||
.PARAMETER Launch | ||
If $true, opens the new Presentation Url in your default browser | ||
.EXAMPLE | ||
New-GSPresentation -Title "Finance Presentation" -Launch | ||
Creates a new Presentation titled "Finance Presentation" and opens it in the browser on creation | ||
#> | ||
[OutputType('Google.Apis.Slides.v1.Data.Presentation')] | ||
[cmdletbinding()] | ||
Param | ||
( | ||
[parameter(Mandatory = $false,ValueFromPipeline = $true,Position = 0)] | ||
[String] | ||
$Title = "Untitled presentation", | ||
[parameter(Mandatory = $false)] | ||
[Alias('Owner','PrimaryEmail','UserKey','Mail')] | ||
[string] | ||
$User = $Script:PSGSuite.AdminEmail, | ||
[parameter(Mandatory = $false)] | ||
[Alias('Open')] | ||
[Switch] | ||
$Launch | ||
) | ||
Begin { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/drive' | ||
ServiceType = 'Google.Apis.Slides.v1.SlidesService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
} | ||
Process { | ||
try { | ||
$body = New-Object 'Google.Apis.Slides.v1.Data.Presentation' | ||
$body.Title = $Title | ||
Write-Verbose "Creating Presentation '$Title' for user '$User'" | ||
$request = $service.Presentations.Create($body) | ||
$response = $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
if ($Launch) { | ||
$PresentationUrl = (Get-GSDriveFile $response.PresentationId).WebViewLink | ||
Write-Verbose "Launching new presentation at $PresentationUrl" | ||
Start-Process $PresentationUrl | ||
} | ||
$response | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} |