-
-
Notifications
You must be signed in to change notification settings - Fork 40
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 #100 from almenscorner/feature-devicemanagementset…
…tings Feature devicemanagementsettings
- Loading branch information
Showing
15 changed files
with
1,227 additions
and
37 deletions.
There are no files selected for viewing
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,75 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This module backs up all Custom Attribute Shell scripts in Intune. | ||
""" | ||
|
||
import os | ||
import base64 | ||
|
||
from .clean_filename import clean_filename | ||
from .graph_request import makeapirequest | ||
from .graph_batch import batch_assignment, get_object_assignment, batch_request | ||
from .save_output import save_output | ||
from .remove_keys import remove_keys | ||
|
||
# Set MS Graph endpoint | ||
ENDPOINT = "https://graph.microsoft.com/beta/deviceManagement/deviceCustomAttributeShellScripts/" | ||
ASSIGNMENT_ENDPOINT = ( | ||
"https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts" | ||
) | ||
|
||
|
||
# Get all Custom Attribute Shell scripts and save them in specified path | ||
def savebackup(path, output, exclude, token): | ||
""" | ||
Saves all Custom Attribute Shell scripts in Intune to a JSON or YAML file and script files. | ||
:param path: Path to save the backup to | ||
:param output: Format the backup will be saved as | ||
:param exclude: If "assignments" is in the list, it will not back up the assignments | ||
:param token: Token to use for authenticating the request | ||
""" | ||
|
||
config_count = 0 | ||
configpath = path + "/" + "Custom Attributes/" | ||
data = makeapirequest(ENDPOINT, token) | ||
script_ids = [] | ||
for script in data["value"]: | ||
script_ids.append(script["id"]) | ||
|
||
assignment_responses = batch_assignment( | ||
data, | ||
"deviceManagement/deviceCustomAttributeShellScripts/", | ||
"?$expand=assignments", | ||
token, | ||
) | ||
script_data_responses = batch_request( | ||
script_ids, "deviceManagement/deviceCustomAttributeShellScripts/", "", token | ||
) | ||
|
||
for script_data in script_data_responses: | ||
config_count += 1 | ||
if "assignments" not in exclude: | ||
assignments = get_object_assignment(script_data["id"], assignment_responses) | ||
if assignments: | ||
script_data["assignments"] = assignments | ||
|
||
script_data = remove_keys(script_data) | ||
|
||
print("Backing up Custom Attribute: " + script_data["displayName"]) | ||
|
||
# Get filename without illegal characters | ||
fname = clean_filename(script_data["displayName"]) | ||
|
||
# Save Shell script as JSON or YAML depending on configured value in "-o" | ||
save_output(output, configpath, fname, script_data) | ||
|
||
# Save Shell script data to the script data folder | ||
if not os.path.exists(configpath + "Script Data/"): | ||
os.makedirs(configpath + "Script Data/") | ||
decoded = base64.b64decode(script_data["scriptContent"]).decode("utf-8") | ||
f = open(configpath + "Script Data/" + script_data["fileName"], "w") | ||
f.write(decoded) | ||
|
||
return config_count |
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,41 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This module backs up Device Management settings in Intune. | ||
""" | ||
|
||
from .clean_filename import clean_filename | ||
from .graph_request import makeapirequest | ||
from .save_output import save_output | ||
from .remove_keys import remove_keys | ||
|
||
# Set MS Graph endpoint | ||
ENDPOINT = "https://graph.microsoft.com/beta/deviceManagement/settings" | ||
|
||
|
||
# Get settings and save in specified path | ||
def savebackup(path, output, token): | ||
""" | ||
Save Device Management Setting to a JSON or YAML file. | ||
:param path: Path to save the backup to | ||
:param output: Format the backup will be saved as | ||
:param token: Token to use for authenticating the request | ||
""" | ||
|
||
config_count = 0 | ||
|
||
configpath = path + "/" + "Device Management Settings/" | ||
data = makeapirequest(ENDPOINT, token) | ||
|
||
if data: | ||
config_count += 1 | ||
data = remove_keys(data) | ||
print("Backing up Device Management Settings") | ||
|
||
# Get filename without illegal characters | ||
fname = clean_filename("settings") | ||
# Save settings as JSON or YAML depending on configured value in "-o" | ||
save_output(output, configpath, fname, data) | ||
|
||
return config_count |
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
Oops, something went wrong.