Skip to content

Commit 928abeb

Browse files
author
rvdwegen
committed
Minor cleanup/speed improvements
1 parent 4d5c105 commit 928abeb

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

profile.ps1

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@ Write-Information '#### CIPP-API Start ####'
44
Set-Location -Path $PSScriptRoot
55
try {
66
$AppInsightsDllPath = Join-Path $PSScriptRoot 'Shared\AppInsights\Microsoft.ApplicationInsights.dll'
7-
if (Test-Path $AppInsightsDllPath) {
8-
[Reflection.Assembly]::LoadFile($AppInsightsDllPath) | Out-Null
9-
Write-Information 'Application Insights SDK loaded successfully'
10-
} else {
11-
Write-Warning "Application Insights DLL not found at: $AppInsightsDllPath"
12-
}
7+
$null = [Reflection.Assembly]::LoadFile($AppInsightsDllPath)
8+
Write-Information 'Application Insights SDK loaded successfully'
139
} catch {
1410
Write-Warning "Failed to load Application Insights SDK: $($_.Exception.Message)"
1511
}
1612

1713
# Import modules
18-
@('CIPPCore', 'CippExtensions', 'Az.KeyVault', 'Az.Accounts', 'AzBobbyTables') | ForEach-Object {
14+
$Modules = @('CIPPCore', 'CippExtensions', 'Az.Accounts', 'Az.KeyVault', 'AzBobbyTables')
15+
foreach ($Module in $Modules) {
1916
try {
20-
$Module = $_
21-
Import-Module -Name $_ -ErrorAction Stop
17+
Import-Module -Name $Module -ErrorAction Stop
2218
} catch {
2319
Write-LogMessage -message "Failed to import module - $Module" -LogData (Get-CippException -Exception $_) -Sev 'debug'
24-
$_.Exception.Message
20+
Write-Error $_.Exception.Message
2521
}
2622
}
2723

@@ -61,7 +57,7 @@ if ($env:ExternalDurablePowerShellSDK -eq $true) {
6157
}
6258

6359
try {
64-
Disable-AzContextAutosave -Scope Process | Out-Null
60+
$null = Disable-AzContextAutosave -Scope Process
6561
} catch {}
6662

6763
try {
@@ -73,8 +69,7 @@ try {
7369
Write-LogMessage -message 'Could not retrieve keys from Keyvault' -LogData (Get-CippException -Exception $_) -Sev 'debug'
7470
}
7571

76-
Set-Location -Path $PSScriptRoot
77-
$CurrentVersion = (Get-Content .\version_latest.txt).trim()
72+
$CurrentVersion = (Get-Content -Path "$($PSScriptRoot)\version_latest.txt" -Raw).Trim()
7873
$Table = Get-CippTable -tablename 'Version'
7974
Write-Information "Function App: $($env:WEBSITE_SITE_NAME) | API Version: $CurrentVersion | PS Version: $($PSVersionTable.PSVersion)"
8075
$global:CippVersion = $CurrentVersion
@@ -84,7 +79,7 @@ if (!$LastStartup -or $CurrentVersion -ne $LastStartup.Version) {
8479
Write-Information "Version has changed from $($LastStartup.Version ?? 'None') to $CurrentVersion"
8580
if ($LastStartup) {
8681
$LastStartup.Version = $CurrentVersion
87-
$LastStartup | Add-Member -MemberType NoteProperty -Name 'PSVersion' -Value $PSVersionTable.PSVersion.ToString() -Force
82+
Add-Member -InputObject $LastStartup -MemberType NoteProperty -Name 'PSVersion' -Value $PSVersionTable.PSVersion.ToString() -Force
8883
} else {
8984
$LastStartup = [PSCustomObject]@{
9085
PartitionKey = 'Version'

0 commit comments

Comments
 (0)