Skip to content

Commit

Permalink
setupPowerShell: Format the script
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Deshmukh <[email protected]>
  • Loading branch information
surajssd committed Nov 1, 2024
1 parent 222ea84 commit f006ec4
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions linux/powershell/setupPowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ param(
$ProgressPreference = 'SilentlyContinue' # Suppresses progress, which doesn't render correctly in docker

# PowerShellGallery PROD site
$prodGallery = 'https://www.powershellgallery.com/api/v2'
$prodGallery = 'https://www.powershellgallery.com/api/v2'

$script:pscloudshellBlob = $null # Version folder for the pscloudshell blob storage
$shareModulePath = ([System.Management.Automation.Platform]::SelectProductNameForDirectory('SHARED_MODULES'))
Expand All @@ -31,7 +31,7 @@ function Get-DockerfileData {
$script:dockerfileDataObject = Microsoft.PowerShell.Management\Get-Content $dockerFileData | Microsoft.PowerShell.Utility\ConvertFrom-Json
if (-not $script:dockerfileDataObject) {
throw "Error while reading $dockerFileData file."
}
}
$pscloudshellVer = $script:dockerfileDataObject.PSCloudShellVersion
$script:pscloudshellBlob = "https://pscloudshellbuild.blob.core.windows.net/$pscloudshellVer"
Write-Output "pscloudshellVersion= $pscloudshellVer; pscloudshellBlob=$script:pscloudshellBlob"
Expand All @@ -57,8 +57,8 @@ function Install-LibMIFile {
function Install-AzAndAzAdModules {
Write-Output "Install-AzAndAdModules.."
mkdir temp
curl -o az-cmdlets.tar.gz -sSL "https://azpspackage.blob.core.windows.net/release/Az-Cmdlets-latest.tar.gz"
tar -xf az-cmdlets.tar.gz -C temp
curl -o az-cmdlets.tar.gz -sSL "https://azpspackage.blob.core.windows.net/release/Az-Cmdlets-latest.tar.gz"
tar -xf az-cmdlets.tar.gz -C temp
rm az-cmdlets.tar.gz
cd temp

Expand Down Expand Up @@ -118,10 +118,10 @@ try {

if ($image -eq "Base") {
Write-Output "Installing modules from production gallery"
PowerShellGet\Install-Module -Name SHiPS @prodAllUsers
PowerShellGet\Install-Module -Name SHiPS @prodAllUsers
PowerShellGet\Install-Module -Name SQLServer -MaximumVersion $script:dockerfileDataObject.SQLServerModuleMaxVersion @prodAllUsers
PowerShellGet\Install-Module -Name MicrosoftPowerBIMgmt -MaximumVersion $script:dockerfileDataObject.PowerBIMaxVersion @prodAllUsers
PowerShellGet\Install-Module -Name MicrosoftTeams @prodAllUsers
PowerShellGet\Install-Module -Name MicrosoftTeams @prodAllUsers

# MS Graph packages
PowerShellGet\Install-Module -Name Microsoft.Graph.Authentication @prodAllUsers
Expand All @@ -142,25 +142,25 @@ try {
# Installing modules from Azure Powershell and AzureAD
Write-Output "Installing modules from Azure Powershell and AzureAD"
Install-AzAndAzAdModules

# Install modules from PSGallery
Write-Output "Installing modules from production gallery"
PowerShellGet\Install-Module -Name AzurePSDrive @prodAllUsers
Write-Output "Installing modules from production gallery"
PowerShellGet\Install-Module -Name AzurePSDrive @prodAllUsers
PowerShellGet\Install-Module -Name GuestConfiguration -MaximumVersion $script:dockerfileDataObject.GuestConfigurationMaxVersion -ErrorAction SilentlyContinue @prodAllUsers
PowerShellGet\Install-Module -Force PSReadLine @prodAllUsers
PowerShellGet\Install-Module -Name Az.Tools.Predictor @prodAllUsers
PowerShellGet\Install-Module -Name ExchangeOnlineManagement @prodAllUsers
PowerShellGet\Install-Module -Name Microsoft.PowerShell.SecretManagement @prodAllUsers
PowerShellGet\Install-Module -Name Microsoft.PowerShell.SecretStore @prodAllUsers

# With older base image builds, teams 1.1.6 is already installed
# With older base image builds, teams 1.1.6 is already installed
if (Get-Module MicrosoftTeams -ListAvailable) {
# For some odd reason, Update-Module was creating the MicrosoftTeams module twice with different version numbers.
# Uninstalling and then installing it again was the only way to keep it as one module.
# Uninstalling and then installing it again was the only way to keep it as one module.
Uninstall-Module MicrosoftTeams -Force
PowerShellGet\Install-Module -Name MicrosoftTeams @prodAllUsers
} else {
PowerShellGet\Install-Module -Name MicrosoftTeams @prodAllUsers
PowerShellGet\Install-Module -Name MicrosoftTeams @prodAllUsers
}

# Install PSCloudShell modules
Expand All @@ -171,14 +171,14 @@ try {
Write-Output ('Temp Directory: {0}' -f $tempDirectory)
}

# Copy the startup script to the all-users profile
# Copy the startup script to the all-users profile
$psStartupScript = Microsoft.PowerShell.Management\Join-Path $PSHOME 'PSCloudShellStartup.ps1'
Microsoft.PowerShell.Management\Copy-Item -Path $PSScriptRoot\PSCloudShellStartup.ps1 -Destination $psStartupScript

Write-Output "Installing powershell profile to $($PROFILE.AllUsersAllHosts)"
Microsoft.PowerShell.Management\Copy-Item -Path $psStartupScript -Destination $PROFILE.AllUsersAllHosts -Verbose
Write-Output "Installed powershell profile."

# Update PowerShell Core help files in the image, ensure any errors that result in help not being updated does not interfere with the build process
# We want the image to have latest help files when shipped.
Write-Output "Updating help files."
Expand All @@ -187,7 +187,7 @@ try {
}

Write-Output "All modules installed:"
Write-Output (Get-InstalledModule | Sort-Object Name | Select-Object Name, Version, Repository)
Write-Output (Get-InstalledModule | Sort-Object Name | Select-Object Name, Version, Repository)
}
finally {
# Clean-up the PowerShell Gallery registration settings
Expand Down

0 comments on commit f006ec4

Please sign in to comment.