From 500e4022e7cf2a05ff7e984bf3331afbaeed061d Mon Sep 17 00:00:00 2001 From: Alan Renouf Date: Wed, 15 Apr 2020 14:09:13 -0700 Subject: [PATCH] Updated Workspace One Access module to include Get-UEMConfig and Remove-UEMConfig --- .../VMware.WorkspaceOneAccess.psd1 | 4 +- .../VMware.WorkspaceOneAccess.psm1 | 115 ++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psd1 b/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psd1 index b25bf20..d226ed5 100644 --- a/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psd1 +++ b/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psd1 @@ -12,7 +12,7 @@ RootModule = 'VMware.WorkspaceOneAccess.psm1' # Version number of this module. -ModuleVersion = '1.0.0' +ModuleVersion = '1.0.1' # Supported PSEditions # CompatiblePSEditions = @() @@ -37,7 +37,7 @@ PowerShellVersion = '6.0' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Connect-WorkspaceOneAccess','Get-WSDirectory','Get-WSIdentityProvider','Get-WSOrgNetwork','New-WS3rdPartyIdentityProvider','New-WSJitDirectory','Remove-WS3rdPartyIdentityProvider','Remove-WSDirectory' +FunctionsToExport = 'Connect-WorkspaceOneAccess','Get-WSDirectory','Get-WSIdentityProvider','Get-WSOrgNetwork','New-WS3rdPartyIdentityProvider','New-WSJitDirectory','Remove-WS3rdPartyIdentityProvider','Remove-WSDirectory', "Get-UEMConfig", "Remove-UEMConfig" # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psm1 b/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psm1 index 9e2e978..642e14f 100644 --- a/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psm1 +++ b/Modules/VMware.WorkspaceOneAccess/VMware.WorkspaceOneAccess.psm1 @@ -569,4 +569,119 @@ Function Remove-WS3rdPartyIdentityProvider { } else { Write-Host "`nUnable to find Identity Provider $Name" } +} + +Function Get-UEMConfig { +<# + .NOTES + =========================================================================== + Created by: Alan Renouf + Date: 04/15/2020 + Organization: VMware + Blog: http://virtu-al.net + Twitter: @alanrenouf + =========================================================================== + + .SYNOPSIS + Retrieves UEM Configuration from Workspace One Access + .DESCRIPTION + This cmdlet retrieves the UEM Configuration from Workspace One Access + .EXAMPLE + Get-UEMConfig + .EXAMPLE + Get-UEMConfig +#> + Param ( + [Switch]$Troubleshoot + ) + + $directoryHeaders = @{ + "Authorization"=$global:workspaceOneAccessConnection.headers.Authorization; + } + + $directoryUrl = $global:workspaceOneAccessConnection.Server + "/SAAS/jersey/manager/api/tenants/tenant/airwatchoptin/config" + $method = "GET" + + if($Troubleshoot) { + Write-Host -ForegroundColor cyan "`n[DEBUG] - $method`n$directoryUrl`n" + } + + try { + if($PSVersionTable.PSEdition -eq "Core") { + $results = Invoke-Webrequest -Uri $directoryUrl -Method $method -UseBasicParsing -Headers $directoryHeaders -SkipCertificateCheck + } else { + $results = Invoke-Webrequest -Uri $directoryUrl -Method $method -UseBasicParsing -Headers $directoryHeaders + } + } catch { + if($_.Exception.Response.StatusCode -eq "Unauthorized") { + Write-Host -ForegroundColor Red "`nThe Workspace One session is no longer valid, please re-run the Connect-WorkspaceOne cmdlet to retrieve a new token`n" + break + } else { + Write-Error "Error in retrieving UEM Configuration" + Write-Error "`n($_.Exception.Message)`n" + break + } + } + + if($results.StatusCode -eq 200) { + $config = ([System.Text.Encoding]::ASCII.GetString($results.Content) | ConvertFrom-Json) + $config + } +} + +Function Remove-UEMConfig { +<# + .NOTES + =========================================================================== + Created by: Alan Renouf + Date: 04/15/2020 + Organization: VMware + Blog: http://virtu-al.net + Twitter: @alanrenouf + =========================================================================== + + .SYNOPSIS + Removes the UEM Configuration from Workspace One Access + .DESCRIPTION + This cmdlet removes the UEM Configuration from Workspace One Access, there can only be one configuration. + .EXAMPLE + Remove-UEMConfig + .EXAMPLE + Remove-UEMConfig +#> + Param ( + [Switch]$Troubleshoot + ) + + $directoryHeaders = @{ + "Authorization"=$global:workspaceOneAccessConnection.headers.Authorization; + } + + $directoryUrl = $global:workspaceOneAccessConnection.Server + "/SAAS/jersey/manager/api/tenants/tenant/airwatchoptin/config" + $method = "DELETE" + + if($Troubleshoot) { + Write-Host -ForegroundColor cyan "`n[DEBUG] - $method`n$directoryUrl`n" + } + + try { + if($PSVersionTable.PSEdition -eq "Core") { + $results = Invoke-Webrequest -Uri $directoryUrl -Method $method -UseBasicParsing -Headers $directoryHeaders -SkipCertificateCheck + } else { + $results = Invoke-Webrequest -Uri $directoryUrl -Method $method -UseBasicParsing -Headers $directoryHeaders + } + } catch { + if($_.Exception.Response.StatusCode -eq "Unauthorized") { + Write-Host -ForegroundColor Red "`nThe Workspace One session is no longer valid, please re-run the Connect-WorkspaceOne cmdlet to retrieve a new token`n" + break + } else { + Write-Error "Error in deleting UEM Configuration" + Write-Error "`n($_.Exception.Message)`n" + break + } + } + + if($results.StatusCode -eq 200) { + Write-Host "`nSuccessfully deleted UEM Configuration" + } } \ No newline at end of file