From 2ab1a2aaa163ca76ea9ba2bce4cfeb4bb1928478 Mon Sep 17 00:00:00 2001 From: Jef Kazimer Date: Tue, 15 May 2018 22:40:14 -0500 Subject: [PATCH 1/5] Added Manfiest file for PSGallery --- MSCloudIdUtils/MSCloudIdUtils.psd1 | Bin 0 -> 9570 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MSCloudIdUtils/MSCloudIdUtils.psd1 diff --git a/MSCloudIdUtils/MSCloudIdUtils.psd1 b/MSCloudIdUtils/MSCloudIdUtils.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..c456122b60998d43061cb50b761f9c32a097addc GIT binary patch literal 9570 zcmeI2Yfl?T6o%(>rTzyCK0vAlN-j-PsZtyW32ko0kn}6~LTGH`+6IzV`Ri@pXO0iE z<6Rqrh+0(@ve&yibLO1)+-Laf&*kuC_#!NaT6hsoLMxnxZfNVS7Y;%{9EXnXMq#Wc z9lamMH^p%)n%4-MnsuVNt+1odzQ!Nx$tbK$sQVgEMXj&TP}Ik|wnXnRd<@^~`m63c z;l1AczQC*#(P7s8upTzz_nq*KetlP%%c_sUAMuHE&lX6 z1i7p6y*vYvXA_!~Hf$W)FBHR<)GveKRq-IhHPN!zkHEd2eIZHgGP zcah)mdTiXai>>2*WFc(&Osf$iuvD+1h<=QyvP^sszj_}%aG+7dl9Wx!=6zB8D49GD zZ|T`s61MeSmha|}b-tTguctq&HM)`z4?WfOD9Sa|Z_B>mOa$2s&%^FT1XuSgrJV2=(@m;;cGl#mu4H=jUBcDM`!gH-2agVkLOKr~@)=e7)!`h-+Y|!iF0(ig2D?o?!}<(4c6_>`J)eFfQX;dVO=1|9i!HPN(Nz~mr%bOz zCaYf8)?n9cTq(oTsGotNR$VLX#9ofos5ij$y?*y&MTk|J#6RiT#|ihdDW?vR&ab#m zGs;uF!oJo8zsvZ(9(BjasACsr6B(xx>n)S5CYhv>uj`u)~YuL z8+_k9D_PJB4+v4G(0D>vHhlt*3}B z^U*O2$Wg4uzTDw%DL!n<>xL2g;%@HsJkh;+OPXwIp9hT=sV>SFQQvA}>k2@jD?W=| z0k%Q~)r@C_>^D*OroHXz%G)_CR)}deuQqc(N$+!RihbJkIoX!1p6N{HYA&pDWEat@ z_*VRNAeqO)*s!1)^LwxIisFFkq?#P}a zeRF3~sHj7BQ;K_@P|mG@JE~$vI?Yp2G;82Yxq5fiye7vqab+4vC&o2V;VL_aEK-Ow~hVf=vtF}_d75|~PvU48xfRlaadIcqX&gwinuQANg05OE_yCz=D zm&n()qh&}q&wfpOyEQJUZ}8J1dVyjl_gQ{L^143ziUH4cO|rrR+|Zp+({b;e@GLCw zS*Pq*R=_V4o&6}0pHrsu0-xd6`MhDnh8t&WhvLw8@ylEewBkwpe+By8Y8DcP;9&r>AyGfuv||UEaf~g`EZ#Pu*NTzgEl1{s6mL=9w1x zk;5#__Uh;Ds8&nKT00Y(xs3DmK!zapS@vh&o7hGSOS?hUySgr=UuRRoeplk|ft{UL z49UkA{c3t&VM|s_CqqoDX&=GPjLLF-(pzwNB816ACP5xC%Fzzn<}+(HUg|MF#i!YH z;NV$Abr5C7YRwOKE_kZ;GtZ3Ev+-f(8jeYBR^o)JBSiRbA$F$BlE{l6bmty}t#L|Z zdsCoTtnV!vUbbUKM0_>rGr)vB7~+bZpK&*v5Ap#%%{jqN^c_2wpi4=6kTrEJcq^3P U-z>c> Date: Tue, 15 May 2018 23:36:28 -0500 Subject: [PATCH 2/5] Updated Manfiest with Disclaimer, removed export-function in PSM1, and removed reference to AzureAD in PSD1 --- MSCloudIdUtils/MSCloudIdUtils.psd1 | Bin 9570 -> 10792 bytes MSCloudIdUtils/MSCloudIdUtils.psm1 | 20 -------------------- 2 files changed, 20 deletions(-) diff --git a/MSCloudIdUtils/MSCloudIdUtils.psd1 b/MSCloudIdUtils/MSCloudIdUtils.psd1 index c456122b60998d43061cb50b761f9c32a097addc..ab7685e7aff34aecab0399f1caa6713b7a543cd8 100644 GIT binary patch delta 1063 zcmd5*OHLF~6g@_0Q$_~H8PWLC46qYzKSKk=vOiJ^U6txaaY)dHiqMkoR-=ijEtphX zffJ_2mAC*MxB>?*z;o_<5C|J!@Lt__?(f`t>;8FqIQa5=aS01>n8W38H_^vS^pGN> zl<-IwRbMYGMh*ogwA-pa*BaH~^(&>r2Vzs~5}n{J_VJohj8Axnagf_Yb}8@SfcKcM zA+;lH)32b<$YKsDNw;lL_6=tyykg9PHp)Du#g=)!x7gE7J|}p?Ba%8zw9z5y7IKo$ zFyNiCoFjdN=SE@@Qa@zM`}DeJ=h*6emRp`F_o!sesf9ImKEXO0ko&2z{8gKwqc*kH zXgWPgj(87UqB%X{<3K)T5w*&+JM2?zn zAflu~o>|&9Zd2|Af6>)z(~@d>eZG`Z~No^G{41dX&ASH(wHXN!J+Bo zFy_YT_B+E(tA5Vhxuk##So!`dnf>;lHXr#t Date: Thu, 24 May 2018 16:43:25 -0700 Subject: [PATCH 3/5] Removed Import-Module on install --- MSCloudIdUtils/MSCloudIdUtils.psm1 | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/MSCloudIdUtils/MSCloudIdUtils.psm1 b/MSCloudIdUtils/MSCloudIdUtils.psm1 index 54e45b2..d575133 100644 --- a/MSCloudIdUtils/MSCloudIdUtils.psm1 +++ b/MSCloudIdUtils/MSCloudIdUtils.psm1 @@ -139,7 +139,7 @@ function Initialize-ActiveDirectoryAuthenticationLibrary() { Write-Host "Fixing Active Directory Authentication Library package directories ..." -ForegroundColor Yellow $adalPackageDirectories | Remove-Item -Recurse -Force | Out-Null - Write-Host "Not able to load ADAL assembly. Delete the Nugets folder under" $modulePath ", restart PowerShell session and try again ..." + Write-Host ("Not able to load ADAL assembly. Delete the Nugets folder under {0}, restart PowerShell session and try again ..." -f $modulePath) return $false } } @@ -301,7 +301,7 @@ Function Get-MSCloudIdGraphAPIAccessTokenFromAppKey $body = @{grant_type="client_credentials";resource="https://graph.microsoft.com";client_id=$ClientID;client_secret=$ClientSecret} $oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$TenantDomain/oauth2/token?api-version=1.0 -Body $body - if ($oauth.access_token -eq $null) + if ($null -eq $oauth.access_token) { throw "ERROR: No Access Token" } @@ -540,7 +540,7 @@ Function Invoke-MSCloudIdAzureADGraphQuery while (-not [String]::IsNullOrEmpty($queryUrl)) { $batchResult = (Invoke-WebRequest -Headers $headerParams -Uri $queryUrl).Content | ConvertFrom-Json - if ($batchResult.value -ne $null) + if ($null -ne $batchResult.value) { $queryResults += $batchResult.value } @@ -554,14 +554,14 @@ Function Invoke-MSCloudIdAzureADGraphQuery $odataNextLink = $batchResult | Select-Object -ExpandProperty "@odata.nextLink" -ErrorAction SilentlyContinue - if ($odataNextLink -ne $null) + if ($null -ne $odataNextLink) { $queryUrl = $odataNextLink } else { $odataNextLink = $batchResult | Select-Object -ExpandProperty "odata.nextLink" -ErrorAction SilentlyContinue - if ($odataNextLink -ne $null) + if ($null -ne $odataNextLink) { $absoluteUri = [Uri]"https://bogus/$odataNextLink" $skipToken = $absoluteUri.Query.TrimStart("?") @@ -621,7 +621,7 @@ Function Invoke-MSCloudIdMSGraphQuery while (-not [String]::IsNullOrEmpty($queryUrl)) { $batchResult = (Invoke-WebRequest -Headers $headerParams -Uri $queryUrl).Content | ConvertFrom-Json - if ($batchResult.value -ne $null) + if ($null -ne $batchResult.value) { $queryResults += $batchResult.value } @@ -635,14 +635,14 @@ Function Invoke-MSCloudIdMSGraphQuery $odataNextLink = $batchResult | Select-Object -ExpandProperty "@odata.nextLink" -ErrorAction SilentlyContinue - if ($odataNextLink -ne $null) + if ($null -ne $odataNextLink) { $queryUrl = $odataNextLink } else { $odataNextLink = $batchResult | Select-Object -ExpandProperty "odata.nextLink" -ErrorAction SilentlyContinue - if ($odataNextLink -ne $null) + if ($null -ne $odataNextLink) { $absoluteUri = [Uri]"https://bogus/$odataNextLink" $skipToken = $absoluteUri.Query.TrimStart("?") @@ -726,7 +726,9 @@ $script:TenantSkus = $null Function Get-AzureADTenantSkus { - if ($script:TenantSkus -eq $null) + [CmdletBinding()] + param() + if ($null -eq $script:TenantSkus) { $script:TenantSkus = Get-AzureADSubscribedSku } @@ -762,7 +764,7 @@ Function Get-MSCloudIdUserLastSigninDateTime #If we had at least one result, then get-member will retrieve the property metadata $atLeastOneSignIn = $signInActivity | Get-Member userId - if ($atLeastOneSignIn -eq $null) + if ($null -eq $atLeastOneSignIn) { Write-Output $null } @@ -800,14 +802,14 @@ Function Get-MSCloudIdAppStaleLicensingReportByUser $skuString = "" - if ($userSkus -ne $null) + if ($Null -ne $userSkus) { $skuString = "" foreach ($userSku in $userSkus) { - $skuName = $TenantSKUs | where {$_.SkuId -eq $userSku.SkuId} | Select-Object -ExpandProperty SkuPartNumber + $skuName = $TenantSKUs | Where-Object {$_.SkuId -eq $userSku.SkuId} | Select-Object -ExpandProperty SkuPartNumber $skuString += $skuName + ";" } @@ -815,7 +817,7 @@ Function Get-MSCloudIdAppStaleLicensingReportByUser $signinStaleStatus = $null - if ($LastSignIn -eq $null) + if ($null -eq $LastSignIn) { $signinStaleStatus = "Stale" } @@ -1040,9 +1042,9 @@ Function Remove-MSCloudIdSyncUsers Write-Progress -Id 10 -Activity "Removing On-Premises users from your tenant..." -CurrentOperation "Connecting to Azure AD" Connect-MsolService Write-Progress -Id 10 -Activity "Removing On-Premises users from your tenant..." -CurrentOperation "Removing users the cloud" - $UsersToRemove = Get-MsolUser -Synchronized | Where {$_.UserPrincipalName -notlike "Sync*"} - $UsersToRemove | %{Remove-MsolUser -ObjectId $_.ObjectId -Force } - Get-MsolUser -ReturnDeletedUsers | %{ Remove-MsolUser -ObjectId $_.ObjectId -RemoveFromRecycleBin -Force } + $UsersToRemove = Get-MsolUser -Synchronized | Where-Object {$_.UserPrincipalName -notlike "Sync*"} + $UsersToRemove | ForEach-Object {Remove-MsolUser -ObjectId $_.ObjectId -Force } + Get-MsolUser -ReturnDeletedUsers | ForEach-Object { Remove-MsolUser -ObjectId $_.ObjectId -RemoveFromRecycleBin -Force } $UsersCount = $UsersToRemove | Measure-Object | Select-Object -ExpandProperty Count "$UsersCount have been deleted from the tenant. To Resynchronize, clean the Azure AD Connect connector spaces and force an Initial Sync Cycle" } @@ -1215,7 +1217,7 @@ function ConvertFrom-MSCloudIDJWT { $DecodedJwt = Decode-JWT -rawToken $Token } - Write-Host ($DecodedJwt | Select headers,claims | ConvertTo-Json) + Write-Host ($DecodedJwt | Select-Object headers,claims | ConvertTo-Json) return $DecodedJwt } @@ -1237,7 +1239,7 @@ function Install-MSCloudIdUtilsModule param() $myDocumentsModuleFolderIsInPSModulePath = $false - [Environment]::GetEnvironmentVariable("PSModulePath") -Split ';' | % { + [Environment]::GetEnvironmentVariable("PSModulePath") -Split ';' | ForEach-Object { if ($_.ToLower() -eq ([Environment]::GetFolderPath("MyDocuments") + "\WindowsPowerShell\Modules").ToLower()){ $myDocumentsModuleFolderIsInPSModulePath = $true } @@ -1289,7 +1291,7 @@ function Install-MSCloudIdUtilsModule Copy-Item "$PSScriptRoot\MSCloudIdUtils.psm1" -Destination $modulePath -Force - Import-Module MSCloudIdUtils + Get-Command -Module MSCloudIdUtils } From d1347d16359ea5d7f3bc1d8729f26281d4972209 Mon Sep 17 00:00:00 2001 From: Jef Kazimer Date: Thu, 24 May 2018 16:59:14 -0700 Subject: [PATCH 4/5] Renamed Decode-JWT to ConvertFrom-RawToken to adhere to approved verbs --- MSCloudIdUtils/MSCloudIdUtils.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MSCloudIdUtils/MSCloudIdUtils.psm1 b/MSCloudIdUtils/MSCloudIdUtils.psm1 index d575133..4ddfa2b 100644 --- a/MSCloudIdUtils/MSCloudIdUtils.psm1 +++ b/MSCloudIdUtils/MSCloudIdUtils.psm1 @@ -1169,7 +1169,7 @@ function Convert-FromBase64StringWithNoPadding([string]$data) return [System.Convert]::FromBase64String($data) } -function Decode-JWT([string]$rawToken) +function ConvertFrom-RawToken([string]$rawToken) { $parts = $rawToken.Split('.'); $headers = [System.Text.Encoding]::UTF8.GetString((Convert-FromBase64StringWithNoPadding $parts[0])) @@ -1211,11 +1211,11 @@ function ConvertFrom-MSCloudIDJWT if ($Recurse) { $decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Token)) - $DecodedJwt = Decode-JWT -rawToken $decoded + $DecodedJwt = ConvertFrom-RawToken -rawToken $decoded } else { - $DecodedJwt = Decode-JWT -rawToken $Token + $DecodedJwt = ConvertFrom-RawToken -rawToken $Token } Write-Host ($DecodedJwt | Select-Object headers,claims | ConvertTo-Json) return $DecodedJwt From 906c287a8946b817eab9bda588fc51a005ef9ead Mon Sep 17 00:00:00 2001 From: Jef Kazimer Date: Fri, 25 May 2018 09:45:01 -0700 Subject: [PATCH 5/5] Renamed unapproved verb for internal cmdlets --- MSCloudIdUtils/MSCloudIdUtils.psm1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MSCloudIdUtils/MSCloudIdUtils.psm1 b/MSCloudIdUtils/MSCloudIdUtils.psm1 index 4ddfa2b..bf13f0d 100644 --- a/MSCloudIdUtils/MSCloudIdUtils.psm1 +++ b/MSCloudIdUtils/MSCloudIdUtils.psm1 @@ -1289,9 +1289,7 @@ function Install-MSCloudIdUtilsModule } - Copy-Item "$PSScriptRoot\MSCloudIdUtils.psm1" -Destination $modulePath -Force - - + Get-Command -Module MSCloudIdUtils }