From 16001171162c199f82d8152435dba2aec903c19d Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Sun, 7 Apr 2019 01:08:57 -0500 Subject: [PATCH 1/7] updated Get-GSDriveFileList to include Fields parameter --- PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 index 5a687ca9..0164a9be 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 @@ -28,6 +28,9 @@ function Get-GSDriveFileList { .PARAMETER Corpora Comma-separated list of bodies of items (files/documents) to which the query applies. Supported bodies are 'User', 'Domain', 'TeamDrive' and 'AllTeamDrives'. 'AllTeamDrives' must be combined with 'User'; all other values must be used in isolation. Prefer 'User' or 'TeamDrive' to 'AllTeamDrives' for efficiency. + .PARAMETER Fields + The specific fields to fetch for the listed files. + .PARAMETER Spaces A comma-separated list of spaces to query within the corpus. Supported values are 'Drive', 'AppDataFolder' and 'Photos'. @@ -64,6 +67,9 @@ function Get-GSDriveFileList { [Switch] $IncludeTeamDriveItems, [parameter(Mandatory = $false)] + [String[]] + $Fields = @('files','kind','nextPageToken'), + [parameter(Mandatory = $false)] [ValidateSet('user','domain','teamDrive')] [String] $Corpora, @@ -113,7 +119,6 @@ function Get-GSDriveFileList { try { $request = $service.Files.List() $request.SupportsTeamDrives = $true - $request.Fields = 'files,kind,nextPageToken' if ($PageSize) { $request.PageSize = $PageSize } @@ -123,6 +128,9 @@ function Get-GSDriveFileList { $FilterFmt = ($PSBoundParameters[$key] -join " and ") -replace " -eq ","=" -replace " -like ",":" -replace " -match ",":" -replace " -contains ",":" -creplace "'True'","True" -creplace "'False'","False" -replace " -in "," in " -replace " -le ",'<=' -replace " -ge ",">=" -replace " -gt ",'>' -replace " -lt ",'<' -replace " -ne ","!=" -replace " -and "," and " -replace " -or "," or " -replace " -not "," not " $request.Q = $FilterFmt } + Fields { + $request.Fields = "$($Fields -join ",")" + } Spaces { $request.$key = $($PSBoundParameters[$key] -join ",") } @@ -133,12 +141,15 @@ function Get-GSDriveFileList { } } } - if ($FilterFmt) { - Write-Verbose "Getting all Drive Files for User '$User' matching Filter: $FilterFmt" + $baseVerbose = "Getting" + if ($Fields) { + $baseVerbose += " Fields [$($Fields -join ",")] of" } - else { - Write-Verbose "Getting all Drive Files for User '$User'" + $baseVerbose += " all Drive Files for User '$User'" + if ($FilterFmt) { + $baseVerbose += " matching Filter: $FilterFmt" } + Write-Verbose $baseVerbose [int]$i = 1 do { $result = $request.Execute() From 309794c7b057503b5f1ec6d4725d0a8765e314fd Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Sun, 7 Apr 2019 01:11:03 -0500 Subject: [PATCH 2/7] updated Get-GSDriveFileList to include Fields parameter --- PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 index 0164a9be..0b7fb401 100644 --- a/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 +++ b/PSGSuite/Public/Drive/Get-GSDriveFileList.ps1 @@ -102,6 +102,9 @@ function Get-GSDriveFileList { $PSBoundParameters['Filter'] = @("'$ParentFolderId' in parents") } } + if ($Fields -notcontains '*' -and $Fields -notcontains 'nextPageToken') { + $Fields += 'nextPageToken' + } } Process { if ($User -ceq 'me') { From a2f05965ec021a0d096d5883834de0ac79f20705 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Thu, 18 Apr 2019 23:52:45 -0500 Subject: [PATCH 3/7] saving updates to rebase --- PSGSuite/PSGSuite.psd1 | 2 +- .../Get-GSUserLicenseListPrivate.ps1 | 70 ++++++++++++------ .../Get-PSGSuiteServiceCache.ps1 | 12 ++- .../Public/Gmail/New-GSGmailSMIMEInfo.ps1 | 8 +- .../Public/Licensing/Get-GSUserLicense.ps1 | 47 +++++++++--- PSGSuite/lib/net45/Google.Apis.Gmail.v1.dll | Bin 102400 -> 102400 bytes .../netstandard1.3/Google.Apis.Gmail.v1.dll | Bin 102400 -> 102400 bytes 7 files changed, 101 insertions(+), 38 deletions(-) diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index b91479ba..a56897a8 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -95,7 +95,7 @@ # Prerelease = '-alpha' # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'GSuite', 'Google', 'Apps', 'API', 'Drive', 'Gmail', 'Admin', 'Automation', 'PSEdition_Core', 'PSEdition_Desktop' + Tags = 'GSuite', 'Google', 'Apps', 'API', 'Drive', 'Gmail', 'Admin', 'Automation', 'PSEdition_Core', 'PSEdition_Desktop', 'Windows', 'Linux', 'Mac' # A URL to the license for this module. LicenseUri = 'https://github.com/scrthq/PSGSuite/blob/master/LICENSE' diff --git a/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 b/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 index dd1287c0..4dbaf9e6 100644 --- a/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 +++ b/PSGSuite/Private/ListPrivate/Get-GSUserLicenseListPrivate.ps1 @@ -3,12 +3,12 @@ function Get-GSUserLicenseListPrivate { Param ( [parameter(Mandatory = $false)] - [ValidateSet("Google-Apps","Google-Drive-storage","Google-Vault")] + [ValidateSet("Google-Apps","Google-Drive-storage","Google-Vault","Cloud-Identity","Cloud-Identity-Premium")] [string[]] - $ProductID = @("Google-Apps","Google-Drive-storage","Google-Vault"), + $ProductID = @("Google-Apps","Google-Drive-storage","Google-Vault","Cloud-Identity","Cloud-Identity-Premium"), [parameter(Mandatory = $false)] [Alias("SkuId")] - [ValidateSet("G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee","1010020020")] + [ValidateSet("Cloud-Identity","Cloud-Identity-Premium","Drive-Enterprise","G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee","1010020020","1010060001","1010010001","1010050001")] [string] $License, [parameter(Mandatory = $false)] @@ -25,23 +25,28 @@ function Get-GSUserLicenseListPrivate { $service = New-GoogleService @serviceParams if ($License) { $ProductID = @{ - '1010020020' = 'Google-Apps' - 'G-Suite-Enterprise' = 'Google-Apps' - 'Google-Apps-Unlimited' = 'Google-Apps' - 'Google-Apps-For-Business' = 'Google-Apps' - 'Google-Apps-For-Postini' = 'Google-Apps' - 'Google-Apps-Lite' = 'Google-Apps' - 'Google-Vault' = 'Google-Vault' - 'Google-Vault-Former-Employee' = 'Google-Vault' - 'Google-Drive-storage-20GB' = 'Google-Drive-storage' - 'Google-Drive-storage-50GB' = 'Google-Drive-storage' - 'Google-Drive-storage-200GB' = 'Google-Drive-storage' - 'Google-Drive-storage-400GB' = 'Google-Drive-storage' - 'Google-Drive-storage-1TB' = 'Google-Drive-storage' - 'Google-Drive-storage-2TB' = 'Google-Drive-storage' - 'Google-Drive-storage-4TB' = 'Google-Drive-storage' - 'Google-Drive-storage-8TB' = 'Google-Drive-storage' - 'Google-Drive-storage-16TB' = 'Google-Drive-storage' + 'Cloud-Identity' = @('101001') # Cloud-Identity + '1010010001' = @('101001') # Cloud-Identity + 'Cloud-Identity-Premium' = @('101005') # Cloud-Identity-Premium + '1010050001' = @('101005') # Cloud-Identity-Premium + '1010020020' = @('Google-Apps') # G-Suite-Enterprise + '1010060001' = @('Google-Apps') # Drive-Enterprise + 'G-Suite-Enterprise' = @('Google-Apps') + 'Google-Apps-Unlimited' = @('Google-Apps') + 'Google-Apps-For-Business' = @('Google-Apps') + 'Google-Apps-For-Postini' = @('Google-Apps') + 'Google-Apps-Lite' = @('Google-Apps') + 'Google-Vault' = @('Google-Vault') + 'Google-Vault-Former-Employee' = @('Google-Vault') + 'Google-Drive-storage-20GB' = @('Google-Drive-storage') + 'Google-Drive-storage-50GB' = @('Google-Drive-storage') + 'Google-Drive-storage-200GB' = @('Google-Drive-storage') + 'Google-Drive-storage-400GB' = @('Google-Drive-storage') + 'Google-Drive-storage-1TB' = @('Google-Drive-storage') + 'Google-Drive-storage-2TB' = @('Google-Drive-storage') + 'Google-Drive-storage-4TB' = @('Google-Drive-storage') + 'Google-Drive-storage-8TB' = @('Google-Drive-storage') + 'Google-Drive-storage-16TB' = @('Google-Drive-storage') }[$License] } $response = @() @@ -49,9 +54,28 @@ function Get-GSUserLicenseListPrivate { Process { try { foreach ($prodId in $ProductID) { + switch ($prodId) { + "Cloud-Identity" { + $prodId = "101001" + } + "Cloud-Identity-Premium" { + $prodId = "101005" + } + } if ($License) { - if ($License -eq "G-Suite-Enterprise") { - $License = "1010020020" + switch ($License) { + "G-Suite-Enterprise" { + $License = "1010020020" + } + "Drive-Enterprise" { + $License = "1010060001" + } + "Cloud-Identity" { + $License = "1010010001" + } + "Cloud-Identity-Premium" { + $License = "1010050001" + } } $request = $service.LicenseAssignments.ListForProductAndSku($prodId,$License,$Script:PSGSuite.Domain) } @@ -89,4 +113,4 @@ function Get-GSUserLicenseListPrivate { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Authentication/Get-PSGSuiteServiceCache.ps1 b/PSGSuite/Public/Authentication/Get-PSGSuiteServiceCache.ps1 index e4230a4f..3b464bdf 100644 --- a/PSGSuite/Public/Authentication/Get-PSGSuiteServiceCache.ps1 +++ b/PSGSuite/Public/Authentication/Get-PSGSuiteServiceCache.ps1 @@ -10,6 +10,11 @@ function Get-PSGSuiteServiceCache { $SessionKey = @($User,$ServiceType,$(($Scope | Sort-Object) -join ";")) -join ";" + .PARAMETER IncludeKeys + If $true, returns the full service cache dictionary including keys. + + Defaults to $false. + .EXAMPLE Get-PSGSuiteServiceCache #> @@ -26,6 +31,11 @@ function Get-PSGSuiteServiceCache { } Process { Write-Verbose "Getting cached session list" - $script:_PSGSuiteSessions.Values + if ($IncludeKeys) { + $script:_PSGSuiteSessions + } + else { + $script:_PSGSuiteSessions.Values + } } } diff --git a/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 b/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 index 05a10727..72ae80dc 100644 --- a/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 +++ b/PSGSuite/Public/Gmail/New-GSGmailSMIMEInfo.ps1 @@ -80,15 +80,17 @@ function New-GSGmailSMIMEInfo { $body.$key = (New-Object PSCredential "user",$PSBoundParameters[$key]).GetNetworkCredential().Password } Pkcs12 { - $p12String = Convert-Base64 -From NormalString -To WebSafeBase64String -String "$([System.IO.File]::ReadAllText((Resolve-Path $PSBoundParameters[$key]).Path))" - $body.$key = $p12String + ###$p12String = Convert-Base64 -From NormalString -To WebSafeBase64String -String "$([System.IO.File]::ReadAllText((Resolve-Path $PSBoundParameters[$key]).Path))" + ###$body.$key = $p12String + $body.$key = [string]([System.IO.File]::ReadAllBytes((Resolve-Path $PSBoundParameters[$key]).Path)) } Default { - $body.$prop = $PSBoundParameters[$prop] + $body.$key = $PSBoundParameters[$key] } } } Write-Verbose "Adding new S/MIME of SendAsEmail '$SendAsEmail' for user '$User' using Certificate '$Pkcs12'" + Write-Verbose "Pkcs12: $($body.Pkcs12)" $request = $service.Users.Settings.SendAs.SmimeInfo.Insert($body,$User,$SendAsEmail) $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru } diff --git a/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 b/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 index f910ddc2..5c2d43ff 100644 --- a/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 +++ b/PSGSuite/Public/Licensing/Get-GSUserLicense.ps1 @@ -34,13 +34,13 @@ function Get-GSUserLicense { $User, [parameter(Mandatory = $false)] [Alias("SkuId")] - [ValidateSet("G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee","1010020020")] + [ValidateSet("Cloud-Identity","Cloud-Identity-Premium","Drive-Enterprise","G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee","1010020020","1010060001","1010010001","1010050001")] [string] $License, [parameter(Mandatory = $false,ParameterSetName = "List")] - [ValidateSet("Google-Apps","Google-Drive-storage","Google-Vault")] + [ValidateSet("Google-Apps","Google-Drive-storage","Google-Vault","Cloud-Identity","Cloud-Identity-Premium")] [string[]] - $ProductID = @("Google-Apps","Google-Drive-storage","Google-Vault"), + $ProductID = @("Google-Apps","Google-Drive-storage","Google-Vault","Cloud-Identity","Cloud-Identity-Premium"), [parameter(Mandatory = $false,ParameterSetName = "List")] [Alias("MaxResults")] [ValidateRange(1,1000)] @@ -55,7 +55,12 @@ function Get-GSUserLicense { } $service = New-GoogleService @serviceParams $productHash = @{ - '1010020020' = 'Google-Apps' + 'Cloud-Identity' = '101001' # Cloud-Identity + '1010010001' = '101001' # Cloud-Identity + 'Cloud-Identity-Premium' = '101005' # Cloud-Identity-Premium + '1010050001' = '101005' # Cloud-Identity-Premium + '1010020020' = 'Google-Apps' # G-Suite-Enterprise + '1010060001' = 'Google-Apps' # Drive-Enterprise 'G-Suite-Enterprise' = 'Google-Apps' 'Google-Apps-Unlimited' = 'Google-Apps' 'Google-Apps-For-Business' = 'Google-Apps' @@ -86,19 +91,41 @@ function Get-GSUserLicense { elseif ($U -notlike "*@*.*") { $U = "$($U)@$($Script:PSGSuite.Domain)" } - if ($License) { + if ($PSBoundParameters.ContainsKey('License')) { Write-Verbose "Getting License SKU '$License' for User '$U'" - if ($License -eq "G-Suite-Enterprise") { - $License = "1010020020" + switch ($License) { + "G-Suite-Enterprise" { + $License = "1010020020" + } + "Drive-Enterprise" { + $License = "1010060001" + } + "Cloud-Identity" { + $License = "1010010001" + } + "Cloud-Identity-Premium" { + $License = "1010050001" + } } $request = $service.LicenseAssignments.Get($productHash[$License],$License,$U) $request.Execute() } else { - foreach ($license in (@("G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee") | Sort-Object)) { + foreach ($license in (@("Cloud-Identity","Cloud-Identity-Premium","Drive-Enterprise","G-Suite-Enterprise","Google-Apps-Unlimited","Google-Apps-For-Business","Google-Apps-For-Postini","Google-Apps-Lite","Google-Drive-storage-20GB","Google-Drive-storage-50GB","Google-Drive-storage-200GB","Google-Drive-storage-400GB","Google-Drive-storage-1TB","Google-Drive-storage-2TB","Google-Drive-storage-4TB","Google-Drive-storage-8TB","Google-Drive-storage-16TB","Google-Vault","Google-Vault-Former-Employee") | Sort-Object)) { Write-Verbose "Getting License SKU '$License' for User '$U'" - if ($License -eq "G-Suite-Enterprise") { - $License = "1010020020" + switch ($License) { + "G-Suite-Enterprise" { + $License = "1010020020" + } + "Drive-Enterprise" { + $License = "1010060001" + } + "Cloud-Identity" { + $License = "1010010001" + } + "Cloud-Identity-Premium" { + $License = "1010050001" + } } try { $request = $service.LicenseAssignments.Get($productHash[$License],$License,$U) diff --git a/PSGSuite/lib/net45/Google.Apis.Gmail.v1.dll b/PSGSuite/lib/net45/Google.Apis.Gmail.v1.dll index cf388b3a5d833458540669139275252508769252..9a378d8a4643f81892b4ad4c902eb1657d6300d3 100644 GIT binary patch delta 302 zcmZozz}B#UZ9)gjlClSLC-(R-3ruEgyuI}{qqY(gJKJ^+WyTO&ffH9hiSxgcai18) zSYt4;b=~%y1jZzBW>XX6?H9`#KXcTx#^^j^{V~~$RlT~mWtH!itM`|Na?I8GtkD@0 zUc>XXM<7L2Z)NEFJ^2pdQ+%&k-ir@Aw|CY){t0%U@7|xoo#Id>CA&r;T)69jmrLku znF|vu3@Yz(B>uQyyGLPDuDYb`Ww-9#-~A@7IpZ-ews_@%KAZb~d!<*Fc{|^}T2mn`GbVC3D delta 302 zcmZozz}B#UZ9)gjBI%z!6MKA^$$Qy0S9&5Br z4;!+Lf#ea7)-_lv| z_V1jqpIz0P`QAyUCJNfxy*pCHQXS=x^66U1#nANgQ$1JZdl>yPdiYCZGk-?ao8pE4 z)?WMgZpD?~e3d5`s(n(oFF!sn_FL7dTj$~@aq@~XU1OH0VkqdBy4&h83v=+uVc2-jc69(h$Kf4+G86oWHy}gXqP-bBhqsey0 IKF0ry0MHwK>i_@% delta 314 zcmZozz}B#UZ9)f2RFLn_i9NoI{~B*?y~U`b#B`l?JBKo3fvv!k4yNq0(bpX}NoT(o zIr(+V_KpNbe{p6LOVjPQ${9a#)Y~2UJ#le+;G}mfWk2MO1Zpf^y?;s{ukS(6OQ%_O zNqXhZIvmvbruTl&jKnn)_P>rwdT_jl=UP?!)}m`?`3o3|oM(hW|y5dgWt0qAO+7U-oi} zFaW^;=?(vuS!b&l$AZknqRJQ}14Bz)10!7n z^X(fN8SgN0U1w!rP-9?Z0Qz@Y3u7ERs|kZ8gX#94-HiQ=5cc%mUPfyuv#^QLWIJOY H<9|i~$^3e^ From 7510a89cb644770ade3b812c9fbecb86b64be33e Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Thu, 18 Apr 2019 23:52:50 -0500 Subject: [PATCH 4/7] saving updates to rebase --- .../Clear-PSGSuiteServiceCache.ps1 | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 PSGSuite/Public/Authentication/Clear-PSGSuiteServiceCache.ps1 diff --git a/PSGSuite/Public/Authentication/Clear-PSGSuiteServiceCache.ps1 b/PSGSuite/Public/Authentication/Clear-PSGSuiteServiceCache.ps1 new file mode 100644 index 00000000..5d2169b9 --- /dev/null +++ b/PSGSuite/Public/Authentication/Clear-PSGSuiteServiceCache.ps1 @@ -0,0 +1,37 @@ +function Clear-PSGSuiteServiceCache { + <# + .SYNOPSIS + Clears the dictionary of cached service objects created with New-GoogleService. + + .DESCRIPTION + Clears the dictionary of cached service objects created with New-GoogleService. + + .EXAMPLE + Clear-PSGSuiteServiceCache + #> + [CmdletBinding()] + Param () + Begin{ + if (-not $script:_PSGSuiteSessions) { + $script:_PSGSuiteSessions = @{} + } + $toRemove = @() + } + Process { + if (-not $script:_PSGSuiteSessions.Keys.Count) { + Write-Verbose "There are no current cached sessions to clear!" + } + else { + foreach ($key in $script:_PSGSuiteSessions.Keys) { + Write-Verbose "Clearing cached session with key: $key" + $script:_PSGSuiteSessions[$key].Service.Dispose() + $toRemove += $key + } + } + } + End { + foreach ($key in $toRemove) { + $script:_PSGSuiteSessions.Remove($key) + } + } +} From 21cf309b23f66eb08bd8c48ec115e05309afd604 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Wed, 24 Apr 2019 23:13:42 -0500 Subject: [PATCH 5/7] ***NO_CI*** adding additional updates --- PSGSuite/Public/Authentication/New-GoogleService.ps1 | 5 +++-- PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/PSGSuite/Public/Authentication/New-GoogleService.ps1 b/PSGSuite/Public/Authentication/New-GoogleService.ps1 index 37cb81bd..6405b83a 100644 --- a/PSGSuite/Public/Authentication/New-GoogleService.ps1 +++ b/PSGSuite/Public/Authentication/New-GoogleService.ps1 @@ -25,6 +25,7 @@ function New-GoogleService { Write-Verbose "Using matching cached service for user '$User'" $script:_PSGSuiteSessions[$sessionKey].Acknowledged = $true } + $script:_PSGSuiteSessions[$sessionKey].LastUsed = Get-Date $script:_PSGSuiteSessions[$sessionKey] | Select-Object -ExpandProperty Service } else { @@ -96,12 +97,12 @@ function New-GoogleService { ApplicationName = "PSGSuite - $env:USERNAME" } ) - $issued = Get-Date $script:_PSGSuiteSessions[$sessionKey] = ([PSCustomObject]@{ User = $User Scope = $Scope Service = $svc - Issued = $issued + Issued = Get-Date + LastUsed = Get-Date Acknowledged = $false }) return $svc diff --git a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 index 36580b6f..b8b8ef69 100644 --- a/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 +++ b/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1 @@ -163,7 +163,7 @@ function Start-GSDriveFileUpload { if ($Description) { $body.Description = $Description } - $stream = New-Object 'System.IO.FileStream' $detPart.FullName,([System.IO.FileMode]::Open),([System.IO.FileAccess]::Read),([System.IO.FileShare]::Delete + [System.IO.FileShare]::ReadWrite) + $stream = New-Object 'System.IO.FileStream' $detPart.FullName,([System.IO.FileMode]::Open),([System.IO.FileAccess]::Read),([System.IO.FileShare]"Delete, ReadWrite") $request = $service.Files.Create($body,$stream,$contentType) $request.QuotaUser = $User $request.SupportsTeamDrives = $true From 9f5d63063ae9634dca609064ec3e70b60898878b Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Wed, 24 Apr 2019 23:58:01 -0500 Subject: [PATCH 6/7] updates --- CHANGELOG.md | 15 +++++++++++++++ PSGSuite/PSGSuite.psd1 | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0e40bba..0a6fa860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog * [Changelog](#changelog) + * [2.26.2](#2262) * [2.26.1](#2261) * [2.26.0](#2260) * [2.25.3](#2253) @@ -83,6 +84,20 @@ *** +## 2.26.2 + +* [Issue #177](https://github.com/scrthq/PSGSuite/issues/177) + * Added: `Fields` parameter to `Get-GSDriveFileList` +* [Issue #178](https://github.com/scrthq/PSGSuite/issues/178) + * Fixed: `Start-GSDriveFileUpload` failing on PowerShell 4.0 +* [Issue #179](https://github.com/scrthq/PSGSuite/issues/179) + * Added: `Ims` parameter to both `New-GSUser` and `Update-GSUser` + * Added: `Add-GSUserIM` function to create correct type for new `Ims` parameter. +* Miscellaneous + * Added: `Clear-PSGSuiteServiceCache` to clear the cache and dispose of any remaining open web clients. + * Improved overall service caching. + * Added: Support for `Cloud-Identity` licenses for `Get-GSUserLicense` + ## 2.26.1 * [Issue #172](https://github.com/scrthq/PSGSuite/issues/172) diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index a56897a8..d3a970cb 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.26.1' + ModuleVersion = '2.26.2' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' From f04e5077396c7d4846aec2733708117beab37d3c Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Thu, 25 Apr 2019 00:43:08 -0500 Subject: [PATCH 7/7] v2.26.2 ## 2.26.2 * [Issue #177](https://github.com/scrthq/PSGSuite/issues/177) * Added: Fields parameter to Get-GSDriveFileList * [Issue #178](https://github.com/scrthq/PSGSuite/issues/178) * Fixed: Start-GSDriveFileUpload failing on PowerShell 4.0 * [Issue #179](https://github.com/scrthq/PSGSuite/issues/179) * Added: Ims parameter to both New-GSUser and Update-GSUser * Added: Add-GSUserIm function to create correct type for new Ims parameter. * Miscellaneous * Added: Clear-PSGSuiteServiceCache to clear the cache and dispose of any remaining open web clients. * Improved overall service caching. * Added: Support for Cloud-Identity licenses for Get-GSUserLicense * Added: OutputType for all applicable Helper functions (i.e. Add-GSUserIm) --- CHANGELOG.md | 3 +- .../Public/Helpers/Add-GSEventAttendee.ps1 | 29 +- .../Public/Helpers/Add-GSGmailSmtpMsa.ps1 | 1 + PSGSuite/Public/Helpers/Add-GSUserAddress.ps1 | 3 +- PSGSuite/Public/Helpers/Add-GSUserEmail.ps1 | 3 +- .../Public/Helpers/Add-GSUserExternalId.ps1 | 3 +- PSGSuite/Public/Helpers/Add-GSUserIm.ps1 | 134 +++++++++ .../Public/Helpers/Add-GSUserLocation.ps1 | 1 + .../Public/Helpers/Add-GSUserOrganization.ps1 | 3 +- PSGSuite/Public/Helpers/Add-GSUserPhone.ps1 | 3 +- .../Public/Helpers/Add-GSUserRelation.ps1 | 1 + .../Public/Helpers/Add-GSUserSchemaField.ps1 | 19 +- PSGSuite/Public/Users/New-GSUser.ps1 | 28 +- PSGSuite/Public/Users/Update-GSUser.ps1 | 258 ++++++++++-------- README.md | 15 + 15 files changed, 349 insertions(+), 155 deletions(-) create mode 100644 PSGSuite/Public/Helpers/Add-GSUserIm.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6fa860..9fbaef37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,11 +92,12 @@ * Fixed: `Start-GSDriveFileUpload` failing on PowerShell 4.0 * [Issue #179](https://github.com/scrthq/PSGSuite/issues/179) * Added: `Ims` parameter to both `New-GSUser` and `Update-GSUser` - * Added: `Add-GSUserIM` function to create correct type for new `Ims` parameter. + * Added: `Add-GSUserIm` function to create correct type for new `Ims` parameter. * Miscellaneous * Added: `Clear-PSGSuiteServiceCache` to clear the cache and dispose of any remaining open web clients. * Improved overall service caching. * Added: Support for `Cloud-Identity` licenses for `Get-GSUserLicense` + * Added: `OutputType` for all applicable Helper functions (i.e. `Add-GSUserIm`) ## 2.26.1 diff --git a/PSGSuite/Public/Helpers/Add-GSEventAttendee.ps1 b/PSGSuite/Public/Helpers/Add-GSEventAttendee.ps1 index e533bc84..6b7a534d 100644 --- a/PSGSuite/Public/Helpers/Add-GSEventAttendee.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSEventAttendee.ps1 @@ -2,43 +2,44 @@ function Add-GSEventAttendee { <# .SYNOPSIS Adds an event attendee to a calendar event - + .DESCRIPTION Adds an event attendee to a calendar event - + .PARAMETER Email The email address of the attendee - + .PARAMETER AdditionalGuests How many additional guests, if any - + .PARAMETER Comment Attendee comment - + .PARAMETER DisplayName The attendee's name, if available - + .PARAMETER Optional Whether this is an optional attendee - + .PARAMETER Organizer Whether the attendee is the organizer of the event - + .PARAMETER Resource Whether the attendee is a resource - + .PARAMETER ResponseStatus - The attendee's response status. - - Possible values are: + The attendee's response status. + + Possible values are: * "NeedsAction": The attendee has not responded to the invitation. * "Declined": The attendee has declined the invitation. * "Tentative": The attendee has tentatively accepted the invitation. * "Accepted": The attendee has accepted the invitation - + .PARAMETER InputObject Used for pipeline input of an existing UserAddress object to strip the extra attributes and prevent errors #> + [OutputType('Google.Apis.Calendar.v3.Data.EventAttendee')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( @@ -114,4 +115,4 @@ function Add-GSEventAttendee { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Helpers/Add-GSGmailSmtpMsa.ps1 b/PSGSuite/Public/Helpers/Add-GSGmailSmtpMsa.ps1 index 041ab199..e6180604 100644 --- a/PSGSuite/Public/Helpers/Add-GSGmailSmtpMsa.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSGmailSmtpMsa.ps1 @@ -43,6 +43,7 @@ function Add-GSGmailSmtpMsa { Updates Joe's SendAs settings for his work SendAs alias, including signature and SmtpMsa settings. #> + [OutputType('Google.Apis.Gmail.v1.Data.SmtpMsa')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( diff --git a/PSGSuite/Public/Helpers/Add-GSUserAddress.ps1 b/PSGSuite/Public/Helpers/Add-GSUserAddress.ps1 index c398089a..aaab6558 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserAddress.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserAddress.ps1 @@ -67,6 +67,7 @@ function Add-GSUserAddress { Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserAddress')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( @@ -163,4 +164,4 @@ function Add-GSUserAddress { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Helpers/Add-GSUserEmail.ps1 b/PSGSuite/Public/Helpers/Add-GSUserEmail.ps1 index 9cbba6df..bc20fc53 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserEmail.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserEmail.ps1 @@ -40,6 +40,7 @@ function Add-GSUserEmail { Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserEmail')] [CmdletBinding()] Param ( @@ -97,4 +98,4 @@ function Add-GSUserEmail { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Helpers/Add-GSUserExternalId.ps1 b/PSGSuite/Public/Helpers/Add-GSUserExternalId.ps1 index 2ac47a23..ab3c64d1 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserExternalId.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserExternalId.ps1 @@ -39,6 +39,7 @@ function Add-GSUserExternalId { Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( @@ -94,4 +95,4 @@ function Add-GSUserExternalId { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Helpers/Add-GSUserIm.ps1 b/PSGSuite/Public/Helpers/Add-GSUserIm.ps1 new file mode 100644 index 00000000..a71432c1 --- /dev/null +++ b/PSGSuite/Public/Helpers/Add-GSUserIm.ps1 @@ -0,0 +1,134 @@ +function Add-GSUserIm { + <# + .SYNOPSIS + Builds an IM object to use when creating or updating a User + + .DESCRIPTION + Builds an IM object to use when creating or updating a User + + .PARAMETER CustomProtocol + If the protocol value is custom_protocol, this property holds the custom protocol's string. + + .PARAMETER CustomType + If the value of type is custom, this property contains the custom type. + + .PARAMETER Im + The user's IM network ID. + + .PARAMETER Primary + If this is the user's primary IM. Only one entry in the IM list can have a value of true. + + .PARAMETER Protocol + An IM protocol identifies the IM network. The value can be a custom network or the standard network. + + Acceptable values are: + * "aim": AOL Instant Messenger protocol + * "custom_protocol": A custom IM network protocol + * "gtalk": Google Talk protocol + * "icq": ICQ protocol + * "jabber": Jabber protocol + * "msn": MSN Messenger protocol + * "net_meeting": Net Meeting protocol + * "qq": QQ protocol + * "skype": Skype protocol + * "yahoo": Yahoo Messenger protocol + + +"aim","custom_protocol","gtalk","icq","jabber","msn","net_meeting","qq","skype","yahoo" + + .PARAMETER Type + The type of the IM account. + + Acceptable values are: + * "custom" + * "home" + * "other" + * "work" + + .PARAMETER InputObject + Used for pipeline input of an existing IM object to strip the extra attributes and prevent errors + + .EXAMPLE + $address = Add-GSUserAddress -Country USA -Locality Dallas -PostalCode 75000 Region TX -StreetAddress '123 South St' -Type Work -Primary + + $phone = Add-GSUserPhone -Type Work -Value "(800) 873-0923" -Primary + + $extId = Add-GSUserExternalId -Type Login_Id -Value jsmith2 + + $email = Add-GSUserEmail -Type work -Address jsmith@contoso.com + + $im = Add-GSUserIm -Type work -Protocol custom_protocol -CustomProtocol spark -Im jsmithertons100 + + New-GSUser -PrimaryEmail john.smith@domain.com -GivenName John -FamilyName Smith -Password (ConvertTo-SecureString -String 'Password123' -AsPlainText -Force) -ChangePasswordAtNextLogin -OrgUnitPath "/Users/New Hires" -IncludeInGlobalAddressList -Addresses $address -Phones $phone -ExternalIds $extId -Emails $email -Ims $im + + Creates a user named John Smith and adds their work address, work phone, IM, login_id and alternate non gsuite work email to the user object. + #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserIm')] + [CmdletBinding()] + Param + ( + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $CustomProtocol, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $CustomType, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [String] + $Im, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [Switch] + $Primary, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [ValidateSet("aim","custom_protocol","gtalk","icq","jabber","msn","net_meeting","qq","skype","yahoo")] + [String] + $Protocol, + [Parameter(Mandatory = $false, ParameterSetName = "Fields")] + [ValidateSet('custom', 'home', 'other', 'work')] + [String] + $Type, + [Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "InputObject")] + [Google.Apis.Admin.Directory.directory_v1.Data.UserIm[]] + $InputObject + ) + Begin { + $propsToWatch = @( + 'CustomProtocol' + 'CustomType' + 'Im' + 'Primary' + 'Protocol' + 'Type' + ) + } + Process { + try { + switch ($PSCmdlet.ParameterSetName) { + Fields { + $obj = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserIm' + foreach ($prop in $PSBoundParameters.Keys | Where-Object {$obj.PSObject.Properties.Name -contains $_}) { + $obj.$prop = $PSBoundParameters[$prop] + } + $obj + } + InputObject { + foreach ($iObj in $InputObject) { + $obj = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserIm' + foreach ($prop in $iObj.PSObject.Properties.Name | Where-Object {$obj.PSObject.Properties.Name -contains $_ -and $propsToWatch -contains $_}) { + $obj.$prop = $iObj.$prop + } + $obj + } + } + } + } + catch { + if ($ErrorActionPreference -eq 'Stop') { + $PSCmdlet.ThrowTerminatingError($_) + } + else { + Write-Error $_ + } + } + } +} diff --git a/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 b/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 index 14559d40..52b08b0d 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserLocation.ps1 @@ -40,6 +40,7 @@ function Add-GSUserLocation { Adds a custom user location. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserLocation')] [CmdletBinding()] Param ( diff --git a/PSGSuite/Public/Helpers/Add-GSUserOrganization.ps1 b/PSGSuite/Public/Helpers/Add-GSUserOrganization.ps1 index b0811ef4..9a8a30d7 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserOrganization.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserOrganization.ps1 @@ -33,6 +33,7 @@ function Add-GSUserOrganization { Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( @@ -125,4 +126,4 @@ function Add-GSUserOrganization { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Helpers/Add-GSUserPhone.ps1 b/PSGSuite/Public/Helpers/Add-GSUserPhone.ps1 index 0c1cccfd..4cdc65b4 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserPhone.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserPhone.ps1 @@ -57,6 +57,7 @@ function Add-GSUserPhone { Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserAddress')] [CmdletBinding()] Param ( @@ -115,4 +116,4 @@ function Add-GSUserPhone { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 b/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 index bd62f98a..47dcc66f 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserRelation.ps1 @@ -51,6 +51,7 @@ function Add-GSUserRelation { Creates a user named John Smith and adds their work address, work phone, login_id and alternate non gsuite work email to the user object. #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.UserRelation')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( diff --git a/PSGSuite/Public/Helpers/Add-GSUserSchemaField.ps1 b/PSGSuite/Public/Helpers/Add-GSUserSchemaField.ps1 index 3cb74e0d..a2b2c60f 100644 --- a/PSGSuite/Public/Helpers/Add-GSUserSchemaField.ps1 +++ b/PSGSuite/Public/Helpers/Add-GSUserSchemaField.ps1 @@ -2,13 +2,13 @@ function Add-GSUserSchemaField { <# .SYNOPSIS Builds a UserPhone object to use when creating or updating a Schema - + .DESCRIPTION Builds a UserPhone object to use when creating or updating a Schema - + .PARAMETER FieldName The name of the field - + .PARAMETER FieldType The type of the field. @@ -21,24 +21,25 @@ function Add-GSUserSchemaField { * "INT64": 64-bit integer values. * "PHONE": Phone numbers. * "STRING": String values. - + .PARAMETER Indexed Switch specifying whether the field is indexed or not. Default: true - + .PARAMETER MultiValued A switch specifying whether this is a multi-valued field or not. Default: false - + .PARAMETER ReadAccessType Parameter description - + .PARAMETER InputObject Parameter description - + .EXAMPLE New-GSUserSchema -SchemaName "SDK" -Fields (Add-GSUserSchemaField -FieldName "string" -FieldType STRING -ReadAccessType ADMINS_AND_SELF),(Add-GSUserSchemaField -FieldName "date" -FieldType DATE -ReadAccessType ADMINS_AND_SELF) This command will create a schema named "SDK" with two fields, "string" and "date", readable by ADMINS_AND_SELF #> + [OutputType('Google.Apis.Admin.Directory.directory_v1.Data.SchemaFieldSpec')] [CmdletBinding(DefaultParameterSetName = "InputObject")] Param ( @@ -102,4 +103,4 @@ function Add-GSUserSchemaField { } } } -} \ No newline at end of file +} diff --git a/PSGSuite/Public/Users/New-GSUser.ps1 b/PSGSuite/Public/Users/New-GSUser.ps1 index d92581ca..ae5f76af 100644 --- a/PSGSuite/Public/Users/New-GSUser.ps1 +++ b/PSGSuite/Public/Users/New-GSUser.ps1 @@ -45,6 +45,11 @@ function New-GSUser { This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId[]' object type. You can create objects of this type easily by using the function 'Add-GSUserExternalId' + .PARAMETER Ims + The IM objects of the user + + This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserIm[]' object type. You can create objects of this type easily by using the function 'Add-GSUserIm' + .PARAMETER Locations The Location objects of the user @@ -151,6 +156,9 @@ function New-GSUser { [Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId[]] $ExternalIds, [parameter(Mandatory = $false)] + [Google.Apis.Admin.Directory.directory_v1.Data.UserIm[]] + $Ims, + [parameter(Mandatory = $false)] [Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]] $Locations, [parameter(Mandatory = $false)] @@ -232,17 +240,19 @@ function New-GSUser { } $body.ExternalIds = $extIdList } - Locations { - if ($null -ne $Locations) { - $locationList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserLocation]' - foreach ($loc in $Locations) { - $locationList.Add($loc) - } - $body.Locations = $locationList + Ims { + $imList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserIm]' + foreach ($im in $Ims) { + $imList.Add($im) } - else { - $toClear['locations'] = $null + $body.Ims = $imList + } + Locations { + $locationList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserLocation]' + foreach ($loc in $Locations) { + $locationList.Add($loc) } + $body.Locations = $locationList } Organizations { $orgList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization]' diff --git a/PSGSuite/Public/Users/Update-GSUser.ps1 b/PSGSuite/Public/Users/Update-GSUser.ps1 index 3c22fb93..88e66d3c 100644 --- a/PSGSuite/Public/Users/Update-GSUser.ps1 +++ b/PSGSuite/Public/Users/Update-GSUser.ps1 @@ -50,6 +50,13 @@ function Update-GSUser { To CLEAR all values for a user, pass `$null` as the value for this parameter. + .PARAMETER Ims + The IM objects of the user + + This parameter expects a 'Google.Apis.Admin.Directory.directory_v1.Data.UserIm[]' object type. You can create objects of this type easily by using the function 'Add-GSUserIm' + + To CLEAR all values for a user, pass `$null` as the value for this parameter. + .PARAMETER Locations The Location objects of the user @@ -164,6 +171,9 @@ function Update-GSUser { [Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId[]] $ExternalIds, [parameter(Mandatory = $false)] + [Google.Apis.Admin.Directory.directory_v1.Data.UserIm[]] + $Ims, + [parameter(Mandatory = $false)] [Google.Apis.Admin.Directory.directory_v1.Data.UserLocation[]] $Locations, [parameter(Mandatory = $false)] @@ -217,146 +227,160 @@ function Update-GSUser { elseif ($U -notlike "*@*.*") { $U = "$($U)@$($Script:PSGSuite.Domain)" } - Write-Verbose "Updating user '$U'" - $userObj = Get-GSUser $U -Verbose:$false - $body = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' - $name = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserName' - $nameUpdated = $false - $toClear = @{} - foreach ($prop in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_ -or $name.PSObject.Properties.Name -contains $_}) { - switch ($prop) { - PrimaryEmail { - if ($PSBoundParameters[$prop] -notlike "*@*.*") { - $PSBoundParameters[$prop] = "$($PSBoundParameters[$prop])@$($Script:PSGSuite.Domain)" - } - $body.$prop = $PSBoundParameters[$prop] - } - GivenName { - $name.$prop = $PSBoundParameters[$prop] - $nameUpdated = $true - } - FamilyName { - $name.$prop = $PSBoundParameters[$prop] - $nameUpdated = $true - } - FullName { - $name.$prop = $PSBoundParameters[$prop] - $nameUpdated = $true - } - Password { - $body.Password = (New-Object PSCredential "user", $Password).GetNetworkCredential().Password - } - CustomSchemas { - $schemaDict = New-Object 'System.Collections.Generic.Dictionary`2[[System.String],[System.Collections.Generic.IDictionary`2[[System.String],[System.Object]]]]' - foreach ($schemaName in $CustomSchemas.Keys) { - $fieldDict = New-Object 'System.Collections.Generic.Dictionary`2[[System.String],[System.Object]]' - $schemaFields = $CustomSchemas[$schemaName] - $schemaFields.Keys | ForEach-Object { - $fieldDict.Add($_, $schemaFields[$_]) + if ($PSCmdlet.ShouldProcess("Updating user '$U'")) { + Write-Verbose "Updating user '$U'" + $userObj = Get-GSUser $U -Verbose:$false + $body = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.User' + $name = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserName' + $nameUpdated = $false + $toClear = @{ } + foreach ($prop in $PSBoundParameters.Keys | Where-Object { $body.PSObject.Properties.Name -contains $_ -or $name.PSObject.Properties.Name -contains $_ }) { + switch ($prop) { + PrimaryEmail { + if ($PSBoundParameters[$prop] -notlike "*@*.*") { + $PSBoundParameters[$prop] = "$($PSBoundParameters[$prop])@$($Script:PSGSuite.Domain)" } - $schemaDict.Add($schemaName, $fieldDict) + $body.$prop = $PSBoundParameters[$prop] } - $body.CustomSchemas = $schemaDict - } - Emails { - $emailList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserEmail]' - foreach ($email in $Emails) { - $emailList.Add($email) + GivenName { + $name.$prop = $PSBoundParameters[$prop] + $nameUpdated = $true } - $body.Emails = $emailList - } - ExternalIds { - if ($null -ne $ExternalIds) { - $extIdList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId]' - foreach ($extId in $ExternalIds) { - $extIdList.Add($extId) - } - $body.ExternalIds = $extIdList + FamilyName { + $name.$prop = $PSBoundParameters[$prop] + $nameUpdated = $true } - else { - $toClear['externalIds'] = $null + FullName { + $name.$prop = $PSBoundParameters[$prop] + $nameUpdated = $true } - } - Locations { - if ($null -ne $Locations) { - $locationList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserLocation]' - foreach ($loc in $Locations) { - $locationList.Add($loc) - } - $body.Locations = $locationList + Password { + $body.Password = (New-Object PSCredential "user", $Password).GetNetworkCredential().Password } - else { - $toClear['locations'] = $null + CustomSchemas { + $schemaDict = New-Object 'System.Collections.Generic.Dictionary`2[[System.String],[System.Collections.Generic.IDictionary`2[[System.String],[System.Object]]]]' + foreach ($schemaName in $CustomSchemas.Keys) { + $fieldDict = New-Object 'System.Collections.Generic.Dictionary`2[[System.String],[System.Object]]' + $schemaFields = $CustomSchemas[$schemaName] + $schemaFields.Keys | ForEach-Object { + $fieldDict.Add($_, $schemaFields[$_]) + } + $schemaDict.Add($schemaName, $fieldDict) + } + $body.CustomSchemas = $schemaDict } - } - Organizations { - if ($null -ne $Organizations) { - $orgList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization]' - foreach ($organization in $Organizations) { - $orgList.Add($organization) + Emails { + $emailList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserEmail]' + foreach ($email in $Emails) { + $emailList.Add($email) } - $body.Organizations = $orgList + $body.Emails = $emailList } - else { - $toClear['organizations'] = $null + ExternalIds { + if ($null -ne $ExternalIds) { + $extIdList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserExternalId]' + foreach ($extId in $ExternalIds) { + $extIdList.Add($extId) + } + $body.ExternalIds = $extIdList + } + else { + $toClear['externalIds'] = $null + } } - } - Relations { - if ($null -ne $Relations) { - $relList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation]' - foreach ($relation in $Relations) { - $relList.Add($relation) + Ims { + if ($null -ne $Ims) { + $imList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserIm]' + foreach ($im in $Ims) { + $imList.Add($im) + } + $body.Ims = $imList + } + else { + $toClear['ims'] = $null } - $body.Relations = $relList } - else { - $toClear['relations'] = $null + Locations { + if ($null -ne $Locations) { + $locationList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserLocation]' + foreach ($loc in $Locations) { + $locationList.Add($loc) + } + $body.Locations = $locationList + } + else { + $toClear['locations'] = $null + } } - } - Phones { - if ($null -ne $Phones) { - $phoneList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserPhone]' - foreach ($phone in $Phones) { - $phoneList.Add($phone) + Organizations { + if ($null -ne $Organizations) { + $orgList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserOrganization]' + foreach ($organization in $Organizations) { + $orgList.Add($organization) + } + $body.Organizations = $orgList + } + else { + $toClear['organizations'] = $null } - $body.Phones = $phoneList } - else { - $toClear['phones'] = $null + Relations { + if ($null -ne $Relations) { + $relList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserRelation]' + foreach ($relation in $Relations) { + $relList.Add($relation) + } + $body.Relations = $relList + } + else { + $toClear['relations'] = $null + } } - } - IsAdmin { - if ($userObj.IsAdmin -eq $PSBoundParameters[$prop]) { - Write-Verbose "User '$U' already has IsAdmin set to '$($userObj.IsAdmin)'" + Phones { + if ($null -ne $Phones) { + $phoneList = New-Object 'System.Collections.Generic.List`1[Google.Apis.Admin.Directory.directory_v1.Data.UserPhone]' + foreach ($phone in $Phones) { + $phoneList.Add($phone) + } + $body.Phones = $phoneList + } + else { + $toClear['phones'] = $null + } } - else { - if ($PSCmdlet.ShouldProcess("Updating user '$U' to IsAdmin '$($PSBoundParameters[$prop])'")) { - Write-Verbose "Updating user '$U' to IsAdmin '$($PSBoundParameters[$prop])'" - $adminBody = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserMakeAdmin' -Property @{ - Status = $PSBoundParameters[$prop] + IsAdmin { + if ($userObj.IsAdmin -eq $PSBoundParameters[$prop]) { + Write-Verbose "User '$U' already has IsAdmin set to '$($userObj.IsAdmin)'" + } + else { + if ($PSCmdlet.ShouldProcess("Updating user '$U' to IsAdmin '$($PSBoundParameters[$prop])'")) { + Write-Verbose "Updating user '$U' to IsAdmin '$($PSBoundParameters[$prop])'" + $adminBody = New-Object 'Google.Apis.Admin.Directory.directory_v1.Data.UserMakeAdmin' -Property @{ + Status = $PSBoundParameters[$prop] + } + $request = $service.Users.MakeAdmin($adminBody, $userObj.Id) + $request.Execute() } - $request = $service.Users.MakeAdmin($adminBody, $userObj.Id) - $request.Execute() } } - } - Default { - $body.$prop = $PSBoundParameters[$prop] + Default { + $body.$prop = $PSBoundParameters[$prop] + } } } - } - if ($nameUpdated) { - $body.Name = $name - } - $request = $service.Users.Update($body, $userObj.Id) - $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru - if ($toClear.Keys.Count) { - $header = @{ - Authorization = "Bearer $(Get-GSToken -Scopes "https://www.googleapis.com/auth/admin.directory.user" -Verbose:$false)" + if ($nameUpdated) { + $body.Name = $name + } + $request = $service.Users.Update($body, $userObj.Id) + $request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $U -PassThru + if ($toClear.Keys.Count) { + $header = @{ + Authorization = "Bearer $(Get-GSToken -Scopes "https://www.googleapis.com/auth/admin.directory.user" -Verbose:$false)" + } + $uri = [Uri]"https://www.googleapis.com/admin/directory/v1/users/$U" + Write-Verbose "Clearing out all values for User '$U' on the following properties: [ $($toClear.Keys -join ", ") ]" + $null = Invoke-RestMethod -Method Put -Uri $uri -Headers $header -Body $($toClear | ConvertTo-Json -Depth 5 -Compress) -ContentType 'application/json' -Verbose:$false -ErrorAction Stop } - $uri = [Uri]"https://www.googleapis.com/admin/directory/v1/users/$U" - Write-Verbose "Clearing out all values for User '$U' on the following properties: [ $($toClear.Keys -join ", ") ]" - $null = Invoke-RestMethod -Method Put -Uri $uri -Headers $header -Body $($toClear | ConvertTo-Json -Depth 5 -Compress) -ContentType 'application/json' -Verbose:$false -ErrorAction Stop } } catch { diff --git a/README.md b/README.md index 5f8067c5..a1c0e76f 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,21 @@ Update-GSSheetValue Export-GSSheet [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) +#### 2.26.2 + +* [Issue #177](https://github.com/scrthq/PSGSuite/issues/177) + * Added: `Fields` parameter to `Get-GSDriveFileList` +* [Issue #178](https://github.com/scrthq/PSGSuite/issues/178) + * Fixed: `Start-GSDriveFileUpload` failing on PowerShell 4.0 +* [Issue #179](https://github.com/scrthq/PSGSuite/issues/179) + * Added: `Ims` parameter to both `New-GSUser` and `Update-GSUser` + * Added: `Add-GSUserIm` function to create correct type for new `Ims` parameter. +* Miscellaneous + * Added: `Clear-PSGSuiteServiceCache` to clear the cache and dispose of any remaining open web clients. + * Improved overall service caching. + * Added: Support for `Cloud-Identity` licenses for `Get-GSUserLicense` + * Added: `OutputType` for all applicable Helper functions (i.e. `Add-GSUserIm`) + #### 2.26.1 * [Issue #172](https://github.com/scrthq/PSGSuite/issues/172)