Skip to content

Instantly share code, notes, and snippets.

@neerajks77
Last active May 1, 2021 04:40
Show Gist options
  • Save neerajks77/b5d10b8d4e91ccf413878272be020964 to your computer and use it in GitHub Desktop.
Save neerajks77/b5d10b8d4e91ccf413878272be020964 to your computer and use it in GitHub Desktop.
This script deploys, installs, and configures the IoT Edge Runtime on the Windows device to configure the device as an edge device to which other leaf devices can connect
#Uninstall the IoT Edge module from the Windows device
. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; Uninstall-IoTEdge -Force
#Deploy the IoT Edge Runtime module to the Windows device
. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; Deploy-IoTEdge -ContainerOs Windows
# Define Variables for the configuration of the edge device using DPS with X509 Certificates
# Note that only .cert and .pem extensions are supported
# The names of the certificates mentioned here are the one's created using the microsoft provided scipt on github.
# The link to the github repossitory is https://github.com/Azure/iotedge/tree/master/tools/CACertificates
$X509IdentityChainCertPath = "<path to the device identity chain cert>\certs\iot-edge-device-identity-<name>-full-chain.cert.pem"
$X509IdentityPrivateKey = "<path to the device identity key cert>\private\iot-edge-device-identity-<name>.key.pem"
$ScopeID = "<scope id of the DPS service from thr overview page>"
# RegId is optional. If provided, it will use the same value for registering the device in IoT with the same name, else will use the individual enrollment registratio id, which is the certificate CN.
#$RegId = "<Registration ID of the individual enrolment or any other custom value>"
#Install the Azure IoT Edge Runtime on the device to configure the device as an Edge device
. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; `
Initialize-IoTEdge -DpsX509 -ScopeId $ScopeID -X509IdentityCertificate $X509IdentityChainCertPath -X509IdentityPrivateKey $X509IdentityPrivateKey
#########################################################################################################################
#IoT Leaf Device Identity Certificate
#Run New-CACertsDevice mydevice to create the new device identity certificate.
#This will create files iot-device-mydevice* that each contain the public key, private key, and PFX respectively.
#IoT Edge Device CA Certificate
#Run New-CACertsEdgeDeviceCA MyEdgeDeviceCA to create the new IoT Edge device CA certificate.
#This will create files iot-edge-device-ca-MyEdgeDeviceCA* that each contain the public key, private key, and PFX respectively.
#IoT Edge Device Identity Certificate
#Run New-CACertsEdgeDeviceIdentity MyEdgeDeviceId to create the new IoT Edge device identity certificate.
#This will create files iot-edge-device-identity-MyEdgeDeviceId* that each contain the public key, private key, and PFX respectively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment