Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new InputObject parameter #262

Merged
merged 5 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions PSGSuite/Public/Drive/Get-GSDriveFileList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@ function Get-GSDriveFileList {
}
}
Process {
if ($User -ceq 'me') {
$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
Resolve-Email ([ref]$User)
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Drive.v3.DriveService'
Expand Down
34 changes: 17 additions & 17 deletions PSGSuite/Public/Drive/Remove-GSDriveFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ function Remove-GSDriveFile {
Deletes a Drive file

.PARAMETER FileId
The unique Id of the file to get
The unique Id(s) of the file(s) to delete

.PARAMETER User
The email or unique Id of the owner of the Drive file

Defaults to the AdminEmail user

.EXAMPLE
Remove-GSDriveFile -User user@domain.com -FileId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976'
Remove-GSDriveFile -FileId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' -User user@domain.com

Deletes the file with ID 1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976 from the user user@domain.com's Drive

.EXAMPLE
Get-GSDriveFileList -ParentFolderId '1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976' -User user@domain.com | Remove-GSDriveFile

Get the file with ID 1rhsAYTOB_vrpvfwImPmWy0TcVa2sgmQa_9u976 from the user user@domain.com's Drive and pipeline
#>
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = "High")]
Param
(
[parameter(Mandatory = $true, Position = 0)]
Param(
[parameter(Mandatory,ValueFromPipelineByPropertyName,Position = 0)]
[Alias('Id')]
[String[]]
$FileId,
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[parameter(ValueFromPipelineByPropertyName,Position = 1)]
[Alias('Owner', 'PrimaryEmail', 'UserKey', 'Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail
)
Process {
if ($User -ceq 'me') {
$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
Resolve-Email ([ref]$User)
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Drive.v3.DriveService'
Expand All @@ -45,12 +45,12 @@ function Remove-GSDriveFile {
$service = New-GoogleService @serviceParams
foreach ($file in $FileId) {
try {
if ($PSCmdlet.ShouldProcess("Deleting File Id '$file' from user '$User'")) {
Write-Verbose "Deleting File Id '$file' from user '$User'"
$request = $service.Files.Delete($file)
if ($PSCmdlet.ShouldProcess("Deleting File Id '$FileId' from user '$User'")) {
Write-Verbose "Deleting File Id '$FileId' from user '$User'"
$request = $service.Files.Delete($FileId)
$request.SupportsAllDrives = $true
$request.Execute()
Write-Verbose "File Id '$file' successfully deleted from user '$User'"
$request.Execute() | Out-Null
Write-Verbose "File Id '$FileId' successfully deleted from user '$User'"
}
}
catch {
Expand Down