forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from KelvinTegelaar/master
[pull] master from KelvinTegelaar:master
- Loading branch information
Showing
303 changed files
with
5,857 additions
and
4,068 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Add-CIPPBPAField { | ||
param ( | ||
$BPAName = 'CIPP Standards v1.0 - Table view', | ||
$FieldName, | ||
$FieldValue, | ||
$StoreAs, | ||
$Tenant | ||
) | ||
$Table = Get-CippTable -tablename 'cachebpav2' | ||
$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant | ||
$CurrentContentsObject = (Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$BPAName' and PartitionKey eq '$($TenantName.customerId)'") | ||
Write-Host "Adding $FieldName to $BPAName for $Tenant. content is $($CurrentContents.RowKey)" | ||
if ($CurrentContentsObject.RowKey) { | ||
$CurrentContents = @{} | ||
$CurrentContentsObject.PSObject.Properties | ForEach-Object { | ||
$CurrentContents[$_.Name] = $_.Value | ||
} | ||
$Result = $CurrentContents | ||
} else { | ||
$Result = @{ | ||
Tenant = "$($TenantName.displayName)" | ||
GUID = "$($TenantName.customerId)" | ||
RowKey = $BPAName | ||
PartitionKey = "$($TenantName.customerId)" | ||
LastRefresh = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z') | ||
} | ||
} | ||
switch -Wildcard ($StoreAs) { | ||
'*bool' { | ||
$Result["$fieldName"] = [bool]$FieldValue | ||
} | ||
'JSON' { | ||
|
||
if ($FieldValue -eq $null) { $JsonString = '{}' } else { $JsonString = (ConvertTo-Json -Depth 15 -InputObject $FieldValue -Compress) } | ||
$Result[$fieldName] = [string]$JsonString | ||
} | ||
'string' { | ||
$Result[$fieldName], [string]$FieldValue | ||
} | ||
'percentage' { | ||
|
||
} | ||
} | ||
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force | ||
} |
74 changes: 37 additions & 37 deletions
74
Modules/CIPPCore/Public/Entrypoints/Invoke-AddAPDevice.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
using namespace System.Net | ||
using namespace System.Net | ||
|
||
Function Invoke-AddAPDevice { | ||
Function Invoke-AddAPDevice { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug" | ||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
|
||
|
||
# Write to the Azure Functions log stream. | ||
Write-Host "PowerShell HTTP trigger function processed a request." | ||
$TenantFilter = (Get-Tenants | Where-Object { $_.defaultDomainName -eq $Request.body.TenantFilter }).customerId | ||
$GroupName = if ($Request.body.Groupname) { $Request.body.Groupname } else { (New-Guid).GUID } | ||
$rawDevices = $request.body.autopilotData | ||
$Devices = ConvertTo-Json @($rawDevices) | ||
Write-Host $Devices | ||
$Result = try { | ||
$CurrentStatus = (New-GraphgetRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$tenantfilter/DeviceBatches" -scope 'https://api.partnercenter.microsoft.com/user_impersonation') | ||
if ($groupname -in $CurrentStatus.items.id) { throw "This device batch name already exists. Please try with another name." } | ||
$body = '{"batchId":"' + $($GroupName) + '","devices":' + $Devices + '}' | ||
$GraphRequest = (New-GraphPostRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$TenantFilter/DeviceBatches" -body $body -scope 'https://api.partnercenter.microsoft.com/user_impersonation') | ||
Write-Host ($GraphRequest | ConvertTo-Json) | ||
Start-Sleep 5 | ||
$NewStatus = New-GraphgetRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$tenantfilter/DeviceBatches" -scope 'https://api.partnercenter.microsoft.com/user_impersonation' | ||
Write-Host $($Newstatus | ConvertTo-Json) | ||
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 | ||
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)" | ||
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" | ||
} | ||
# Write to the Azure Functions log stream. | ||
Write-Host 'PowerShell HTTP trigger function processed a request.' | ||
$TenantFilter = (Get-Tenants | Where-Object { $_.defaultDomainName -eq $Request.body.TenantFilter }).customerId | ||
$GroupName = if ($Request.body.Groupname) { $Request.body.Groupname } else { (New-Guid).GUID } | ||
$rawDevices = $request.body.autopilotData | ||
$Devices = ConvertTo-Json @($rawDevices) | ||
Write-Host $Devices | ||
$Result = try { | ||
$CurrentStatus = (New-GraphgetRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$tenantfilter/DeviceBatches" -scope 'https://api.partnercenter.microsoft.com/user_impersonation') | ||
if ($groupname -in $CurrentStatus.items.id) { throw 'This device batch name already exists. Please try with another name.' } | ||
$body = '{"batchId":"' + $($GroupName) + '","devices":' + $Devices + '}' | ||
$GraphRequest = (New-GraphPostRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$TenantFilter/DeviceBatches" -body $body -scope 'https://api.partnercenter.microsoft.com/user_impersonation') | ||
Write-Host ($GraphRequest | ConvertTo-Json) | ||
Start-Sleep 5 | ||
$NewStatus = New-GraphgetRequest -uri "https://api.partnercenter.microsoft.com/v1/customers/$tenantfilter/DeviceBatches" -scope 'https://api.partnercenter.microsoft.com/user_impersonation' | ||
Write-Host $($Newstatus | ConvertTo-Json) | ||
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 | ||
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)" | ||
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 } | ||
Write-Host $body | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $body | ||
$body = [pscustomobject]@{'Results' = $Result } | ||
Write-Host $body | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $body | ||
|
||
}) | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 23 additions & 60 deletions
83
Modules/CIPPCore/Public/Entrypoints/Invoke-AddAutopilotConfig.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,40 @@ | ||
using namespace System.Net | ||
using namespace System.Net | ||
|
||
Function Invoke-AddAutopilotConfig { | ||
Function Invoke-AddAutopilotConfig { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug" | ||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
|
||
|
||
# Write to the Azure Functions log stream. | ||
Write-Host "PowerShell HTTP trigger function processed a request." | ||
# Write to the Azure Functions log stream. | ||
Write-Host 'PowerShell HTTP trigger function processed a request.' | ||
|
||
# Input bindings are passed in via param block. | ||
$user = $request.headers.'x-ms-client-principal' | ||
$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value | ||
$displayname = $request.body.Displayname | ||
$description = $request.body.Description | ||
$AssignTo = if ($request.body.Assignto -ne "on") { $request.body.Assignto } | ||
$Profbod = $Request.body | ||
$usertype = if ($Profbod.NotLocalAdmin -eq "true") { "standard" } else { "administrator" } | ||
$DeploymentMode = if ($profbod.DeploymentMode -eq "true") { "shared" } else { "singleUser" } | ||
$results = foreach ($Tenant in $tenants) { | ||
try { | ||
$ObjBody = [pscustomobject]@{ | ||
"@odata.type" = "#microsoft.graph.azureADWindowsAutopilotDeploymentProfile" | ||
"displayName" = "$($displayname)" | ||
"description" = "$($description)" | ||
"deviceNameTemplate" = "$($profbod.DeviceNameTemplate)" | ||
"language" = "os-default" | ||
"enableWhiteGlove" = $([bool]($profbod.allowWhiteGlove)) | ||
"deviceType" = "windowsPc" | ||
"extractHardwareHash" = $([bool]($profbod.CollectHash)) | ||
"roleScopeTagIds" = @() | ||
"hybridAzureADJoinSkipConnectivityCheck" = $false | ||
"outOfBoxExperienceSettings" = @{ | ||
"deviceUsageType" = "$DeploymentMode" | ||
"hideEscapeLink" = $([bool]($Profbod.hideChangeAccount)) | ||
"hidePrivacySettings" = $([bool]($Profbod.hidePrivacy)) | ||
"hideEULA" = $([bool]($Profbod.hideTerms)) | ||
"userType" = "$usertype" | ||
"skipKeyboardSelectionPage" = $([bool]($Profbod.Autokeyboard)) | ||
} | ||
} | ||
$Body = ConvertTo-Json -InputObject $ObjBody | ||
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles" -body $body -tenantid $Tenant | ||
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 | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APIName -tenant $($tenant) -message "Assigned autopilot profile $($Displayname) to $AssignTo" -Sev "Info" | ||
} | ||
"Successfully added profile for $($Tenant)" | ||
# Input bindings are passed in via param block. | ||
$Tenants = ($Request.body | Select-Object Select_*).psobject.properties.value | ||
$displayname = $request.body.Displayname | ||
$description = $request.body.Description | ||
$AssignTo = if ($request.body.Assignto -ne 'on') { $request.body.Assignto } | ||
$Profbod = $Request.body | ||
$usertype = if ($Profbod.NotLocalAdmin -eq 'true') { 'standard' } else { 'administrator' } | ||
$DeploymentMode = if ($profbod.DeploymentMode -eq 'true') { 'shared' } else { 'singleUser' } | ||
$results = foreach ($Tenant in $tenants) { | ||
Set-CIPPDefaultAPDeploymentProfile -tenantFilter $tenant -displayname $displayname -description $description -usertype $usertype -DeploymentMode $DeploymentMode -assignto $AssignTo -devicenameTemplate $Profbod.deviceNameTemplate -allowWhiteGlove $Profbod.allowWhiteGlove -CollectHash $Profbod.collectHash -hideChangeAccount $Profbod.hideChangeAccount -hidePrivacy $Profbod.hidePrivacy -hideTerms $Profbod.hideTerms -Autokeyboard $Profbod.Autokeyboard | ||
} | ||
catch { | ||
"Failed to add profile for $($Tenant): $($_.Exception.Message)" | ||
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 | ||
} | ||
|
||
} | ||
|
||
$body = [pscustomobject]@{"Results" = $results } | ||
$body = [pscustomobject]@{'Results' = $results } | ||
|
||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $body | ||
}) | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $body | ||
}) | ||
|
||
|
||
|
||
} | ||
} |
Oops, something went wrong.