-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
226 additions
and
0 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,144 @@ | ||
<# | ||
.SYNOPSIS | ||
Written By John N Lewis | ||
v 1.5 | ||
This script provides an automated deployment capability for DSC and Azure Automation. | ||
.DESCRIPTION | ||
Provides framework for deploying DSC to Azure Automation | ||
#> | ||
|
||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true,Position=0)] | ||
[string] | ||
$AutoAcctName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true,Position=2)] | ||
[string] | ||
$VMName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$NodeName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$ConfigurationName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true,Position=1)] | ||
[string] | ||
$VMresourceGroupName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true,Position=3)] | ||
[string] | ||
$resourceGroupName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$Location = "EastUs", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$VMLocation = "WestUs", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$containerName = "dsc", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$thisfolder = "C:\Templates", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$localfolder = "$thisfolder\dsc", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$destfolder = "dsc", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$OutputFolder = "", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$SourcePath = "", | ||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$nodeconfigpath = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$SubscriptionID = '', | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$TenantID = '', | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$StorageName = "", | ||
|
||
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)] | ||
[string] | ||
$StorageType = "" | ||
|
||
) | ||
# Global | ||
$ErrorActionPreference = "SilentlyContinue" | ||
$date = Get-Date -UFormat "%Y-%m-%d-%H-%M" | ||
$workfolder = Split-Path $script:MyInvocation.MyCommand.Path | ||
|
||
Add-AzureRmAccount | ||
|
||
Function CreateStorage { | ||
Write-Host "Starting Storage Creation.." | ||
$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName.ToLower() -Type $StorageType -Location $Location -ErrorAction Stop -WarningAction SilentlyContinue | ||
#Get-AzureRmStorageAccount -Name $StorageName.ToLower() -ResourceGroupName $ResourceGroupName -WarningAction SilentlyContinue | ft "StorageAccountName" -OutVariable $stracct | ||
Write-Host "Completed Storage Creation" -ForegroundColor White | ||
} # Creates Storage | ||
|
||
Function RegisterAutoDSC { | ||
$ActionAfterReboot = ContinueConfiguration | ||
$configmode = ApplyAndAutocorrect | ||
|
||
Register-AzureRmAutomationDscNode -AutomationAccountName $AutoAcctName -AzureVMName $VMName -ActionAfterReboot $ActionAfterReboot -ConfigurationMode $configmode -RebootNodeIfNeeded $True -ResourceGroupName $resourceGroupName -NodeConfigurationName $ConfigurationName -AzureVMLocation $VMLocation -AzureVMResourceGroup $VMresourceGroupName -Verbose | ||
} | ||
|
||
Function ExportConfig { | ||
Export-AzureRmAutomationDscConfiguration -Name $ConfigurationName -OutputFolder $OutputFolder -AutomationAccountName $AutoAcctName -ResourceGroupName $resourceGroupName -Force -Confirm $False -Verbose | ||
} | ||
Function ExportConfigreport { | ||
Export-AzureRmAutomationDscNodeReportContent -NodeId $NodeName -ResourceGroupName $resourceGroupName -AutomationAccountName $AutoAcctName -OutputFolder $OutputFolder -ReportId | ||
} | ||
|
||
Function ImportConfig { | ||
Import-AzureRmAutomationDscConfiguration -SourcePath $SourcePath -ResourceGroupName $resourceGroupName -AutomationAccountName $AutoAcctName | ||
} | ||
Function ImportNodeConfig { | ||
Import-AzureRmAutomationDscNodeConfiguration -Path $nodeconfigpath -ConfigurationName $ConfigurationName -AutomationAccountName $AutoAcctName -ResourceGroupName $resourceGroupName | ||
} | ||
Function GetMetadata { | ||
Get-AzureRmAutomationDscOnboardingMetaconfig -AutomationAccountName $AutoAcctName -ResourceGroupName $ResourceGroupName | ||
} | ||
Function CompileJob { | ||
Start-AzureRmAutomationDscCompilationJob -ConfigurationName $ConfigurationName -ResourceGroupName $resourceGroupName -AutomationAccountName $AutoAcctName -Parameters -ConfigurationData | ||
} | ||
|
||
|
||
try { | ||
Get-AzureRmResourceGroup -Location $Location -ErrorAction Stop | ||
} | ||
catch { | ||
Write-Host -foregroundcolor Yellow ` | ||
"User has not authenticated, use Add-AzureRmAccount or $($_.Exception.Message)"; ` | ||
continue | ||
} | ||
|
||
New-AzureRmResourceGroup -Name $resourceGroupName -Location $Location -Force -Confirm $False | ||
|
||
Get-AzureRmAutomationAccount -AutomationAccountName $AutoAcctName -ResourceGroupName $ResourceGroupName | ||
Write-Host "------------------------------------------------------------------------------"# | ||
Get-AzureRmAutomationDscCompilationJob -AutomationAccountName $AutoAcctName -ResourceGroupName $ResourceGroupName | ft ConfigurationName | ||
Write-Host "------------------------------------------------------------------------------" | ||
Get-AzureRmAutomationDscNode -AutomationAccountName $AutoAcctName -ResourceGroupName $ResourceGroupName | ft Name, NodeConfigurationName | ||
Write-Host "------------------------------------------------------------------------------" | ||
Get-AzureRmAutomationDscConfiguration -AutomationAccountName $AutoAcctName -ResourceGroupName $ResourceGroupName | ft Name, State | ||
|
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,82 @@ | ||
<# | ||
.SYNOPSIS | ||
Written By John N Lewis | ||
v 1.5 | ||
This script provides an automated deployment capability for DSC Modules and Azure Automation. | ||
.DESCRIPTION | ||
Provides framework for deploying DSC Modules to Azure Automation | ||
#> | ||
$containerName = "dsc" | ||
$ResourceGroupName = "" | ||
$StorageName = "" | ||
$thisfolder = "C:\Templates" | ||
$localfolder = "$thisfolder\dsc" | ||
$destfolder = "Modules" | ||
$ContentLink = "" | ||
$AutoAcctName = "" | ||
$modulename = "" | ||
### Authenticate to Microsoft Azure using Microsoft Account (MSA) or Azure Active Directory (AAD) | ||
|
||
|
||
Function NewModule { | ||
$module = $modulename | ||
$content = $ContentLink | ||
New-AzureRmAutomationModule -Name $module -ContentLink $content -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutoAcctName | ||
} | ||
|
||
Function SetModule { | ||
$module = $modulename | ||
$content = $ContentLink | ||
Set-AzureRmAutomationModule -Name $module -ContentLinkUri $content -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutoAcctName | ||
} | ||
|
||
Function RemoveModule { | ||
$module = $modulename | ||
Remove-AzureRmAutomationModule -Name $module -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutoAcctName -Force -Confirm $false | ||
} | ||
Add-AzureRmAccount | ||
### Create an Azure Resource Manager (ARM) Resource Group | ||
$ResourceGroup = @{ | ||
Name = $ResourceGroupName; | ||
Location = 'EastUs2'; | ||
Force = $true; | ||
} | ||
New-AzureRmResourceGroup @ResourceGroup; | ||
|
||
$StorageAccount = @{ | ||
ResourceGroupName = $ResourceGroupName; | ||
Name = $StorageName; | ||
SkuName = 'Standard_LRS'; | ||
Location = 'EastUS2'; | ||
} | ||
New-AzureRmStorageAccount @StorageAccount; | ||
|
||
### Obtain the Storage Account authentication keys using Azure Resource Manager (ARM) | ||
$Keys = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageName; | ||
|
||
### Use the Azure.Storage module to create a Storage Authentication Context | ||
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageName -StorageAccountKey $Keys[0].Value -ErrorAction SilentlyContinue; | ||
|
||
### Create a Blob Container in the Storage Account | ||
New-AzureStorageContainer -Context $StorageContext -Name dsc -ErrorAction SilentlyContinue; | ||
|
||
### Upload a file to the Microsoft Azure Storage Blob Container | ||
|
||
$storageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageName; | ||
$blobContext = New-AzureStorageContext -StorageAccountName $StorageName -StorageAccountKey $Keys[0].Value -ErrorAction SilentlyContinue; | ||
$files = Get-ChildItem $localFolder | ||
foreach($file in $files) | ||
{ | ||
$fileName = "$localFolder\$file" | ||
$blobName = "$destfolder/$file" | ||
write-host "copying $fileName to $blobName" | ||
Set-AzureStorageBlobContent -File $filename -Container $containerName -Blob $blobName -Context $blobContext -Force -ErrorAction Stop | ||
} | ||
write-host "All files in $localFolder uploaded to $containerName!" | ||
|
||
### Deploy Modules to Automation Acct | ||
|
||
NewModule | ||
|