Skip to content

Commit

Permalink
Merge pull request #5 from santese/AutoPilot-Additions
Browse files Browse the repository at this point in the history
Auto pilot additions
  • Loading branch information
santese authored Oct 4, 2020
2 parents 39c54e9 + 11184b6 commit 2f1c5b6
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microsoft-intune",
"version": "1.1.1",
"version": "1.1.2",
"description": "",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
202 changes: 202 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ interface IOAuthResponse {
access_token: string
}

interface IntuneScript {
displayName: string
description: string
scriptContent: string
runAsAccount: 'system' | 'user'
enforceSignatureCheck: boolean
fileName: string
runAs32Bit: boolean
}

interface AutoPilotUpload {
serialNumber?: string
groupTag?: string
productKey?: string
hardwareIdentifier?: string
assignedUser?: string
}

class Intune {
config: IntuneConfig
domain: string
Expand Down Expand Up @@ -89,6 +107,22 @@ class Intune {
}
}

async getAutopilotDevices (): Promise<object[]> {
try {
const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/windowsAutopilotDeviceIdentities?$top=999`,
{
method: 'GET',
headers: this.reqHeaders
}
)
const resbody = JSON.parse(res.body)
return resbody.value
} catch (err) {
throw err
}
}

async syncDevice (deviceId: string): Promise<object> {
try {
const res = await this._IntuneRequest(
Expand All @@ -104,6 +138,32 @@ class Intune {
}
}

async autopilotUpload ({ serialNumber, groupTag, productKey, hardwareIdentifier, assignedUser }: AutoPilotUpload): Promise<object> {
try {
const postBody = {
'@odata.type': '#microsoft.graph.importedWindowsAutopilotDeviceIdentity',
orderIdentifier: groupTag ?? null,
serialNumber: serialNumber ?? null,
productKey: productKey ?? null,
hardwareIdentifier: hardwareIdentifier ?? null,
assignedUserPrincipalName: assignedUser ?? null
}
console.log(postBody)
const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/importedWindowsAutopilotDeviceIdentities`,
{
method: 'POST',
headers: this.reqHeaders,
body: JSON.stringify(postBody)
}
)
const resbody = JSON.parse(res.body)
return resbody
} catch (err) {
throw err
}
}

async setDeviceName (deviceId: string, newDeviceName: string): Promise<object> {
try {
const res = await this._IntuneRequest(
Expand Down Expand Up @@ -152,6 +212,136 @@ class Intune {
}
}

async getScripts (): Promise<[object]> {
try {
const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/deviceManagementScripts`,
{
method: 'Get',
headers: this.reqHeaders
}
)
const resbody = JSON.parse(res.body)
return resbody.value
} catch (err) {
throw err
}
}

async getScript (scriptId: string): Promise<object> {
try {
const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/deviceManagementScripts/${scriptId}`,
{
method: 'Get',
headers: this.reqHeaders
}
)
const resbody = JSON.parse(res.body)
return resbody
} catch (err) {
throw err
}
}

async createScript ({ displayName, description, scriptContent, fileName, runAsAccount, runAs32Bit = false, enforceSignatureCheck = false }: IntuneScript): Promise<object> {
try {
const postBody = {
'@odata.type': '#microsoft.graph.deviceManagementScript',
displayName: displayName,
description: description,
scriptContent: scriptContent,
runAsAccount: runAsAccount,
enforceSignatureCheck: enforceSignatureCheck,
fileName: fileName,
runAs32Bit: runAs32Bit
}

const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/deviceManagementScripts`,
{
method: 'Post',
headers: this.reqHeaders,
body: JSON.stringify(postBody)
}
)
const resbody = JSON.parse(res.body)
return resbody
} catch (err) {
throw err
}
}

async updateScript (scriptId: string, { displayName, description, scriptContent, fileName, runAsAccount, runAs32Bit = false, enforceSignatureCheck = false }: IntuneScript): Promise<object> {
try {
const postBody = {
'@odata.type': '#microsoft.graph.deviceManagementScript',
displayName: displayName,
description: description,
scriptContent: scriptContent,
runAsAccount: runAsAccount,
enforceSignatureCheck: enforceSignatureCheck,
fileName: fileName,
runAs32Bit: runAs32Bit
}

const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/deviceManagementScripts${scriptId}`,
{
method: 'Patch',
headers: this.reqHeaders,
body: JSON.stringify(postBody)
}
)
const resbody = JSON.parse(res.body)
return resbody
} catch (err) {
throw err
}
}

async deleteScript (scriptId: string): Promise<object> {
try {
const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/deviceManagementScripts/${scriptId}`,
{
method: 'Delete',
headers: this.reqHeaders
}
)
return { statusCode: res.statusCode }
} catch (err) {
throw err
}
}

async createScriptAssignment (scriptId: string, groupIds: string[]): Promise<object> {
try {
const groupAssignments = groupIds.map((e: string) => {
return {
'@odata.type': '#microsoft.graph.deviceManagementScriptGroupAssignment',
targetGroupId: e
}
})

const postBody = {
deviceManagementScriptGroupAssignments: groupAssignments
}

const res = await this._IntuneRequest(
`${this.domain}/deviceManagement/deviceManagementScripts/${scriptId}/assign`,
{
method: 'Post',
headers: this.reqHeaders,
body: JSON.stringify(postBody)
}
)
return { statusCode: res.statusCode }
} catch (err) {
throw err
}
}

async getDevice (deviceId: string): Promise<object> {
try {
const res = await this._IntuneRequest(
Expand Down Expand Up @@ -316,6 +506,18 @@ class Intune {
}
}

async deleteDevice (deviceId: string): Promise<object> {
try {
const res = await this._IntuneRequest(`${this.domain}/deviceManagement/managedDevices/${deviceId}`, {
method: 'DELETE',
headers: this.reqHeaders
})
return { statusCode: res.statusCode }
} catch (err) {
throw err
}
}

async getGroups (): Promise<object[]> {
try {
const res = await this._IntuneRequest(`${this.domain}/groups?$top=999`, {
Expand Down

0 comments on commit 2f1c5b6

Please sign in to comment.