forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.ps1
More file actions
65 lines (59 loc) · 2.6 KB
/
profile.ps1
File metadata and controls
65 lines (59 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Write-Information "CIPP-API Start - PS Version: $($PSVersionTable.PSVersion)"
# Import modules
@('CIPPCore', 'CippExtensions', 'Az.KeyVault', 'Az.Accounts', 'AzBobbyTables') | ForEach-Object {
try {
$Module = $_
Import-Module -Name $_ -ErrorAction Stop
} catch {
Write-LogMessage -message "Failed to import module - $Module" -LogData (Get-CippException -Exception $_) -Sev 'debug'
$_.Exception.Message
}
}
if ($env:ExternalDurablePowerShellSDK -eq $true) {
try {
Import-Module AzureFunctions.PowerShell.Durable.SDK -ErrorAction Stop
Write-Information 'External Durable SDK enabled'
} catch {
Write-LogMessage -message 'Failed to import module - AzureFunctions.PowerShell.Durable.SDK' -LogData (Get-CippException -Exception $_) -Sev 'debug'
$_.Exception.Message
}
}
try {
Disable-AzContextAutosave -Scope Process | Out-Null
} catch {}
try {
if (!$env:SetFromProfile) {
Write-Information "We're reloading from KV"
$Auth = Get-CIPPAuthentication
}
} catch {
Write-LogMessage -message 'Could not retrieve keys from Keyvault' -LogData (Get-CippException -Exception $_) -Sev 'debug'
}
Set-Location -Path $PSScriptRoot
$CurrentVersion = (Get-Content .\version_latest.txt).trim()
$Table = Get-CippTable -tablename 'Version'
Write-Information "Function App: $($env:WEBSITE_SITE_NAME) Version: $CurrentVersion"
$LastStartup = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'Version' and RowKey eq '$($env:WEBSITE_SITE_NAME)'"
if (!$LastStartup -or $CurrentVersion -ne $LastStartup.Version) {
Write-Information "Version has changed from $($LastStartup.Version ?? 'None') to $CurrentVersion"
if ($LastStartup) {
$LastStartup.Version = $CurrentVersion
$LastStartup | Add-Member -MemberType NoteProperty -Name 'PSVersion' -Value $PSVersionTable.PSVersion.ToString()
} else {
$LastStartup = [PSCustomObject]@{
PartitionKey = 'Version'
RowKey = $env:WEBSITE_SITE_NAME
Version = $CurrentVersion
PSVersion = $PSVersionTable.PSVersion.ToString()
}
}
Update-AzDataTableEntity @Table -Entity $LastStartup -Force -ErrorAction SilentlyContinue
try {
Clear-CippDurables
} catch {
Write-LogMessage -message 'Failed to clear durables after update' -LogData (Get-CippException -Exception $_) -Sev 'Error'
}
}
# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
# Enable-AzureRmAlias
# You can also define functions or aliases that can be referenced in any of your PowerShell functions.