Skip to content

Commit

Permalink
AzTable to AzBobbyTables Conversion
Browse files Browse the repository at this point in the history
- AzTable conversion
Add new Activity_ functions for getting / updating rows
Convert all AzTableRow functions
Optimization on DomainAnalyser orchestrator to prevent race condition with log entries

- Misc
Update all Log-Request functions to Write-LogMessage
  • Loading branch information
JohnDuprey committed Jul 20, 2022
1 parent 53802fb commit 35a3504
Show file tree
Hide file tree
Showing 213 changed files with 2,344 additions and 1,688 deletions.
9 changes: 9 additions & 0 deletions Activity_AddOrUpdateTableRows/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bindings": [
{
"name": "TableParams",
"type": "activityTrigger",
"direction": "in"
}
]
}
3 changes: 3 additions & 0 deletions Activity_AddOrUpdateTableRows/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
param($TableParams)

Add-AzDataTableEntity @TableParams
9 changes: 9 additions & 0 deletions Activity_GetAllTableRows/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
]
}
6 changes: 6 additions & 0 deletions Activity_GetAllTableRows/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
param($name)

$Table = Get-CippTable -tablename $name
$Rows = Get-AzDataTableEntity @Table

Write-Output $Rows
6 changes: 3 additions & 3 deletions AddAPDevice/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"


# Write to the Azure Functions log stream.
Expand All @@ -23,12 +23,12 @@ $Result = try {
$NewStatus = New-GraphgetRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$tenantfilter/DeviceBatches" -scope 'https://api.partnercenter.microsoft.com/user_impersonation'
if ($Newstatus.totalcount -eq $CurrentStatus.totalcount) { throw "We could not find the new autopilot device. Please check if your input is correct." }
Write-Host $CurrentStatus.Items
Log-Request -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($Request.body.TenantFilter) -message "Created Autopilot devices group. Group ID is $GroupName" -Sev "Info"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($Request.body.TenantFilter) -message "Created Autopilot devices group. Group ID is $GroupName" -Sev "Info"
"Created Autopilot devices group for $($Request.body.TenantFilter). Group ID is $GroupName"
}
catch {
"$($Request.body.TenantFilter): Failed to create autopilot devices. $($_.Exception.Message)"
Log-Request -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($Request.body.TenantFilter) -message "Failed to create autopilot devices. $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($Request.body.TenantFilter) -message "Failed to create autopilot devices. $($_.Exception.Message)" -Sev "Error"
}

$body = [pscustomobject]@{"Results" = $Result }
Expand Down
21 changes: 12 additions & 9 deletions AddAlert/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value
$Results = foreach ($Tenant in $tenants) {
Expand All @@ -29,22 +29,25 @@ $Results = foreach ($Tenant in $tenants) {
UnusedLicenses = [bool]$Request.body.UnusedLicenses
AppSecretExpiry = [bool]$Request.body.AppSecretExpiry
type = 'Alert'
RowKey = $TenantID
PartitionKey = 'Alert'
}

$TableRow = @{
table = (get-cipptable -TableName 'SchedulerConfig')
rowKey = $TenantID
partitionKey = 'Alert'
$Table = get-cipptable -TableName 'SchedulerConfig'
<#$TableRow = @{
table = ()
property = $CompleteObject
UpdateExisting = $true
}
}#>
Write-Host ($TableRow | ConvertTo-Json)
Add-AzTableRow @TableRow | Out-Null

#Add-AzTableRow @TableRow | Out-Null
Add-AzDataTableEntity @Table -Entity $CompleteObject -Force
"Succesfully added Alert for $($Tenant) to queue."
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Succesfully added Alert for $($Tenant) to queue." -Sev 'Info'
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Succesfully added Alert for $($Tenant) to queue." -Sev 'Info'
}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed to add Alert for for $($Tenant) to queue" -Sev 'Error'
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed to add Alert for for $($Tenant) to queue" -Sev 'Error'
"Failed to add Alert for for $($Tenant) to queue $($_.Exception.message)"
}
}
Expand Down
8 changes: 4 additions & 4 deletions AddAutopilotConfig/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"


# Write to the Azure Functions log stream.
Expand Down Expand Up @@ -43,17 +43,17 @@ $results = foreach ($Tenant in $tenants) {
}
$Body = ConvertTo-Json -InputObject $ObjBody
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles" -body $body -tenantid $Tenant
Log-Request -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Added Autopilot profile $($Displayname)" -Sev "Info"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Added Autopilot profile $($Displayname)" -Sev "Info"
if ($AssignTo) {
$AssignBody = '{"target":{"@odata.type":"#microsoft.graph.allDevicesAssignmentTarget"}}'
$assign = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($GraphRequest.id)/assignments" -tenantid $Tenant -type POST -body $AssignBody
Log-Request -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Assigned autopilot profile $($Displayname) to $AssignTo" -Sev "Info"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Assigned autopilot profile $($Displayname) to $AssignTo" -Sev "Info"
}
"Succesfully added profile for $($Tenant)"
}
catch {
"Failed to add profile for $($Tenant): $($_.Exception.Message)"
Log-Request -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Failed adding Autopilot Profile $($Displayname). Error: $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Failed adding Autopilot Profile $($Displayname). Error: $($_.Exception.Message)" -Sev "Error"
continue
}

Expand Down
6 changes: 3 additions & 3 deletions AddCAPolicy/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value
if ("AllTenants" -in $Tenants) { $Tenants = (Get-Tenants).DefaultDomainName }
Expand Down Expand Up @@ -47,12 +47,12 @@ $results = foreach ($Tenant in $tenants) {
}

$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies" -tenantid $tenant -type POST -body $RawJSON
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Added Conditional Access Policy $($Displayname)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Added Conditional Access Policy $($Displayname)" -Sev "Error"
"Succesfully added Conditional Access Policy for $($Tenant)"
}
catch {
"Failed to add policy for $($Tenant): $($_.Exception.Message)"
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Failed adding Conditional Access Policy $($Displayname). Error: $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($Tenant) -message "Failed adding Conditional Access Policy $($Displayname). Error: $($_.Exception.Message)" -Sev "Error"
continue
}

Expand Down
6 changes: 3 additions & 3 deletions AddCATemplate/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-Host ($request | ConvertTo-Json -Compress)

try {
Expand All @@ -21,12 +21,12 @@ try {
}
$JSON = ($JSON | ConvertTo-Json -Depth 10)
Set-Content "Config\$($GUID).CATemplate.json" -Value ($JSON) -Force
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created Transport Rule Template $($Request.body.name) with GUID $GUID" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created Transport Rule Template $($Request.body.name) with GUID $GUID" -Sev "Debug"
$body = [pscustomobject]@{"Results" = "Successfully added template" }

}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to create Transport Rule Template: $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to create Transport Rule Template: $($_.Exception.Message)" -Sev "Error"
$body = [pscustomobject]@{"Results" = "Intune Template Deployment failed: $($_.Exception.Message)" }
}

Expand Down
6 changes: 3 additions & 3 deletions AddChocoApp/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"


Write-Host "PowerShell HTTP trigger function processed a request."
Expand Down Expand Up @@ -34,10 +34,10 @@ $Results = foreach ($Tenant in $tenants) {
} | ConvertTo-Json -Depth 15
$JSONFile = New-Item -Path ".\ChocoApps.Cache\$((New-Guid).GUID)" -Value $CompleteObject -Force -ErrorAction Stop
"Succesfully added Choco App for $($Tenant) to queue."
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Chocolatey Application $($intunebody.Displayname) queued to add" -Sev "Info"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Chocolatey Application $($intunebody.Displayname) queued to add" -Sev "Info"
}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed to add Chocolatey Application $($intunebody.Displayname) to queue" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed to add Chocolatey Application $($intunebody.Displayname) to queue" -Sev "Error"
"Failed added Choco App for $($Tenant) to queue"
}
}
Expand Down
4 changes: 2 additions & 2 deletions AddChocoApp_OrchestrationStarter/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ param($Request, $TriggerMetadata)
$CurrentlyRunning = Get-Item "ChocoApps.Cache\CurrentlyRunning.txt" -ErrorAction SilentlyContinue | Where-Object -Property LastWriteTime -GT (Get-Date).AddHours(-24)
if ($CurrentlyRunning) {
$Results = [pscustomobject]@{"Results" = "Already running. Please wait for the current instance to finish" }
Log-request -API "ChocoApps" -message "Attempted to start upload but an instance was already running." -sev Info
Write-LogMessage -API "ChocoApps" -message "Attempted to start upload but an instance was already running." -sev Info
}
else {
$InstanceId = Start-NewOrchestration -FunctionName 'Applications_Orchestrator'
Write-Host "Started orchestration with ID = '$InstanceId'"
$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
Log-request -API "ChocoApps" -message "Started uploading applications to tenants" -sev Info
Write-LogMessage -API "ChocoApps" -message "Started uploading applications to tenants" -sev Info
$Results = [pscustomobject]@{"Results" = "Started application queue" }
}
Write-Host ($Orchestrator | ConvertTo-Json)
Expand Down
4 changes: 2 additions & 2 deletions AddChocoApp_OrchestrationStarterTimer/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ try {
$CurrentlyRunning = Get-Item 'ChocoApps.Cache\CurrentlyRunning.txt' -ErrorAction SilentlyContinue | Where-Object -Property LastWriteTime -GT (Get-Date).AddHours(-24)
if ($CurrentlyRunning) {
$Results = [pscustomobject]@{'Results' = 'Already running. Please wait for the current instance to finish' }
Log-request -API 'ChocoApps' -message 'Attempted to start upload but an instance was already running.' -sev Info
Write-LogMessage -API 'ChocoApps' -message 'Attempted to start upload but an instance was already running.' -sev Info
}
else {
$InstanceId = Start-NewOrchestration -FunctionName 'Applications_Orchestrator'
Write-Host "Started orchestration with ID = '$InstanceId'"
$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Timer -InstanceId $InstanceId
Log-request -API 'ChocoApps' -message 'Started uploading applications to tenants' -sev Info
Write-LogMessage -API 'ChocoApps' -message 'Started uploading applications to tenants' -sev Info
$Results = [pscustomobject]@{'Results' = 'Started running analysis' }
}
Write-Host ($Orchestrator | ConvertTo-Json)
Expand Down
6 changes: 3 additions & 3 deletions AddEnrollment/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"


# Write to the Azure Functions log stream.
Expand Down Expand Up @@ -37,12 +37,12 @@ $results = foreach ($Tenant in $tenants) {
$ExistingStatusPage = (New-GraphGetRequest -Uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations" -tenantid $Tenant) | Where-Object { $_.id -like "*DefaultWindows10EnrollmentCompletionPageConfiguration" }
$GraphRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceManagement/deviceEnrollmentConfigurations/$($ExistingStatusPage.ID)" -body $body -Type PATCH -tenantid $tenant
"Succesfully changed default enrollment status page for $($Tenant)"
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Added Autopilot Enrollment Status Page $($Displayname)" -Sev "Info"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Added Autopilot Enrollment Status Page $($Displayname)" -Sev "Info"

}
catch {
"Failed to change default enrollment status page for $($Tenant): $($_.Exception.Message)"
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed adding Autopilot Enrollment Status Page $($Displayname). Error: $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $tenant -message "Failed adding Autopilot Enrollment Status Page $($Displayname). Error: $($_.Exception.Message)" -Sev "Error"
continue
}

Expand Down
6 changes: 3 additions & 3 deletions AddGroup/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$groupobj = $Request.body

Expand Down Expand Up @@ -36,11 +36,11 @@ try {
New-ExoRequest -tenantid $groupobj.tenantid -cmdlet "New-DistributionGroup" -cmdParams $params
}
$body = [pscustomobject]@{"Results" = "Succesfully created group. $($_.Exception.Message)" }
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($groupobj.tenantid) -message "Created group $($groupobj.displayname) with id $($GraphRequest.id) " -Sev "Info"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($groupobj.tenantid) -message "Created group $($groupobj.displayname) with id $($GraphRequest.id) " -Sev "Info"

}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($groupobj.tenantid) -message "Group creation API failed. $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($groupobj.tenantid) -message "Group creation API failed. $($_.Exception.Message)" -Sev "Error"
$body = [pscustomobject]@{"Results" = "Failed to create group. $($_.Exception.Message)" }

}
Expand Down
8 changes: 4 additions & 4 deletions AddIntuneTemplate/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace System.Net
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$GUID = (New-Guid).GUID
try {
Expand All @@ -22,7 +22,7 @@ try {
} | ConvertTo-Json
New-Item Config -ItemType Directory -ErrorAction SilentlyContinue
Set-Content "Config\$($GUID).IntuneTemplate.json" -Value $Object -Force
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created intune policy template named $($Request.body.displayname) with GUID $GUID" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created intune policy template named $($Request.body.displayname) with GUID $GUID" -Sev "Debug"

$body = [pscustomobject]@{"Results" = "Successfully added template" }
}
Expand Down Expand Up @@ -71,13 +71,13 @@ try {
} | ConvertTo-Json
New-Item Config -ItemType Directory -ErrorAction SilentlyContinue
Set-Content "Config\$($GUID).IntuneTemplate.json" -Value $Object -Force
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created intune policy template $($Request.body.displayname) with GUID $GUID using an original policy from a tenant" -Sev "Debug"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created intune policy template $($Request.body.displayname) with GUID $GUID using an original policy from a tenant" -Sev "Debug"

$body = [pscustomobject]@{"Results" = "Successfully added template" }
}
}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Intune Template Deployment failed: $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Intune Template Deployment failed: $($_.Exception.Message)" -Sev "Error"
$body = [pscustomobject]@{"Results" = "Intune Template Deployment failed: $($_.Exception.Message)" }
}

Expand Down
Loading

0 comments on commit 35a3504

Please sign in to comment.