From 4234d2c87716f274277ed1517c0f2f9101a09e85 Mon Sep 17 00:00:00 2001 From: "Yinghua Zeng [MVP]" <28437644+sandytsang@users.noreply.github.com> Date: Sat, 25 Jul 2020 20:05:46 +0300 Subject: [PATCH 1/2] Always create $env:USERPROFILE\.hvtoolscfgpath When use this function initialize a new folder, it didn't update "$env:USERPROFILE\.hvtoolscfgpath" file content, or recreate this new file, so reads hvconfig.json configuration from wrong folder. --- Intune.HV.Tools/Public/Initialize-HVTools.ps1 | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/Intune.HV.Tools/Public/Initialize-HVTools.ps1 b/Intune.HV.Tools/Public/Initialize-HVTools.ps1 index 7de6534..9f3f20f 100644 --- a/Intune.HV.Tools/Public/Initialize-HVTools.ps1 +++ b/Intune.HV.Tools/Public/Initialize-HVTools.ps1 @@ -22,25 +22,20 @@ function Initialize-HVTools { } $cfgPath = "$Path\.hvtools\hvconfig.json" Write-Host " + Creating $cfgPath.. " -ForegroundColor Cyan -NoNewline - if ((Test-Path $cfgPath -ErrorAction SilentlyContinue) -and ($Reset -eq $false)) { - Write-Host "$script:tick (Already created - no need to run this again..)" -ForegroundColor Green - } - else { - $initCfg = @{ - 'hvConfigPath' = $cfgPath - 'images' = @() - "vmPath" = "$Path\.hvtools\tenantVMs" - 'vSwitchName' = $null - 'vLanId' = $null - 'tenantConfig' = @() - } | ConvertTo-Json -Depth 20 - $initCfg | Out-File $cfgPath -Encoding ascii -Force - $cfgPath | Out-File "$env:USERPROFILE\.hvtoolscfgpath" -Encoding ascii -Force - Write-Host $script:tick -ForegroundColor Green - $script:hvConfig = (get-content -Path "$(get-content "$env:USERPROFILE\.hvtoolscfgpath" -ErrorAction SilentlyContinue)" -raw -ErrorAction SilentlyContinue | ConvertFrom-Json) - } + $initCfg = @{ + 'hvConfigPath' = $cfgPath + 'images' = @() + "vmPath" = "$Path\.hvtools\tenantVMs" + 'vSwitchName' = $null + 'vLanId' = $null + 'tenantConfig' = @() + } | ConvertTo-Json -Depth 20 + $initCfg | Out-File $cfgPath -Encoding ascii -Force + $cfgPath | Out-File "$env:USERPROFILE\.hvtoolscfgpath" -Encoding ascii -Force + Write-Host $script:tick -ForegroundColor Green + $script:hvConfig = (get-content -Path "$(get-content "$env:USERPROFILE\.hvtoolscfgpath" -ErrorAction SilentlyContinue)" -raw -ErrorAction SilentlyContinue | ConvertFrom-Json) } catch { Write-Warning $_ } -} \ No newline at end of file +} From eb50482a7b6e47b73c704e22e19c6308ae04b423 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Mon, 27 Jul 2020 18:11:33 +1000 Subject: [PATCH 2/2] fixing multiple policy selection --- Intune.HV.Tools/Private/Get-AutopilotPolicy.ps1 | 3 ++- Intune.HV.Tools/Public/Add-ImageToConfig.ps1 | 2 +- Intune.HV.Tools/Public/Add-NetworkToConfig.ps1 | 2 +- Intune.HV.Tools/Public/Add-TenantToConfig.ps1 | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Intune.HV.Tools/Private/Get-AutopilotPolicy.ps1 b/Intune.HV.Tools/Private/Get-AutopilotPolicy.ps1 index 8218fbc..aef1ff5 100644 --- a/Intune.HV.Tools/Private/Get-AutopilotPolicy.ps1 +++ b/Intune.HV.Tools/Private/Get-AutopilotPolicy.ps1 @@ -33,7 +33,8 @@ function Get-AutopilotPolicy { else { if ($apPolicies.count -gt 1) { Write-Host "Multiple Autopilot policies found - select the correct one.." -ForegroundColor Cyan - $apPol = $apPolicies | Select-Object displayName | Out-GridView -passthru + $selectedAp = $apPolicies | Select-Object displayName | Out-GridView -passthru + $apPol = $apPolicies | Where-Object {$_.displayName -eq $selectedAp.displayName} } else { Write-Host "Policy found - saving to $FileDestination.." -ForegroundColor Cyan diff --git a/Intune.HV.Tools/Public/Add-ImageToConfig.ps1 b/Intune.HV.Tools/Public/Add-ImageToConfig.ps1 index 1eaa7c8..c964261 100644 --- a/Intune.HV.Tools/Public/Add-ImageToConfig.ps1 +++ b/Intune.HV.Tools/Public/Add-ImageToConfig.ps1 @@ -19,7 +19,7 @@ function Add-ImageToConfig { refImagePath = $ReferenceVHDX } $script:hvConfig.images += $newTenant - $script:hvConfig | ConvertTo-Json -Depth 20 | Out-File -FilePath $hvConfig.hvConfigPath -Encoding ascii -Force + $script:hvConfig | ConvertTo-Json -Depth 20 | Out-File -FilePath $script:hvConfig.hvConfigPath -Encoding ascii -Force Write-Host $script:tick -ForegroundColor Green #region Check for ref image - if it's not there, build it if (!(Test-Path -Path $newTenant.refImagePath -ErrorAction SilentlyContinue)) { diff --git a/Intune.HV.Tools/Public/Add-NetworkToConfig.ps1 b/Intune.HV.Tools/Public/Add-NetworkToConfig.ps1 index 866537d..4569df5 100644 --- a/Intune.HV.Tools/Public/Add-NetworkToConfig.ps1 +++ b/Intune.HV.Tools/Public/Add-NetworkToConfig.ps1 @@ -13,7 +13,7 @@ function Add-NetworkToConfig { if ($VLanId) { $script:hvConfig.vLanId = $VLanId } - $script:hvConfig | ConvertTo-Json -Depth 20 | Out-File -FilePath $hvConfig.hvConfigPath -Encoding ascii -Force + $script:hvConfig | ConvertTo-Json -Depth 20 | Out-File -FilePath $script:hvConfig.hvConfigPath -Encoding ascii -Force } catch { $errorMsg = $_ diff --git a/Intune.HV.Tools/Public/Add-TenantToConfig.ps1 b/Intune.HV.Tools/Public/Add-TenantToConfig.ps1 index 49ad867..f5f48c1 100644 --- a/Intune.HV.Tools/Public/Add-TenantToConfig.ps1 +++ b/Intune.HV.Tools/Public/Add-TenantToConfig.ps1 @@ -18,7 +18,7 @@ function Add-TenantToConfig { AdminUpn = $AdminUpn } $script:hvConfig.tenantConfig += $newTenant - $script:hvConfig | ConvertTo-Json -Depth 20 | Out-File -FilePath $hvConfig.hvConfigPath -Encoding ascii -Force + $script:hvConfig | ConvertTo-Json -Depth 20 | Out-File -FilePath $script:hvConfig.hvConfigPath -Encoding ascii -Force } catch { $errorMsg = $_