Install-Module -Name GuestConfiguration -scope AllUsers 
Install-Module -Name Az -scope AllUsers 
Install-Module -Name PSDscResources -scope AllUsers 
Install-Module -Name SecurityPolicyDsc -scope AllUsers 
Install-Module -Name AuditPolicyDsc -scope AllUsers 
Configuration ConveniencePinDisabled { 
    Import-DSCResource -ModuleName 'PSDscResources' 
    Node localhost { 
        Registry "Ensure Turn on convenience PIN sign-in is set to Disabled" { 
            Key = 'HKLM:SoftwarePoliciesMicrosoftWindowsSystem' 
            ValueName = 'AllowDomainPINLogon' 
            ValueType = 'Dword' 
            ValueData = 0 # Corresponds to ‘Disabled’ 
            Ensure = 'Present' 
        } 
    } 
}
ConveniencePinDisabled 
.<YourConfigurationName>.ps1 
# Create a new Guest Configuration package 
$params = @{
    Name          = "<YourConfigurationFileName>"
    Configuration = "<PathToMofFile>"
    Type          = "AuditAndSet" # Can also be 'Audit'
    Force         = $true
}
New-GuestConfigurationPackage @params
# Connect to Azure 
Connect-AzAccount -Tenant '<YourTenantName>'

# Get Azure Storage context from an existing storage account
$StorageAccount = Get-AzStorageAccount -ResourceGroupName '<YourResourceGroupName>' -Name '<YourStorageAccountName>'

if ($StorageAccount) {
    $context = $StorageAccount.Context
    $setParams = @{
        Container = 'package-artifacts'
        File      = '<YourConfigurationName>.zip'
        Context   = $context
    }
    # Upload package to storage
    $blob = Set-AzStorageBlobContent @setParams
    # Get the URI for the uploaded package
    $contentUri = $blob.ICloudBlob.Uri.AbsoluteUri
    Write-Host "File uploaded successfully to $contentUri"
} else {
    Write-Host "Storage account $StorageAccountName not found in resource group $ResourceGroupName"
}
if (!(Get-Module "Az.Storage")) { 
    Write-Output 'Importing Module Az.Storage'
    Install-Module -Name Az.Storage -Repository PSGallery -Force
    Get-Module -ListAvailable -Name Az.Storage -Refresh
}
# generate new GUID
Write-Output 'Generating new GUID'
$guid = [guid]::NewGuid().ToString()
# create policy definition and save locally
$PolicyConfig = @{
PolicyId = $guid
ContentUri = '<ContentURI>'
DisplayName = '<YourDisplayName>'
Description = '<YourDescription>'
Path = './policies'
Platform = 'Windows'
Mode = '<PolicyMode>' # Audit, ApplyAndMonitor, or ApplyAndAutoCorrect
PolicyVersion = '1.0.0'
}
Write-Output ''
Write-Output 'Creating policy definition'
New-GuestConfigurationPolicy @PolicyConfig -Verbose
# Publish policy definition to Azure 
$JsonPath = '.policies<PolicyFileName>.json'
$PolicyJson = Get-Content -Path $JsonPath -Raw
Write-Output ''
Write-Output 'Publishing policy definition to Azure'
New-AzPolicyDefinition -Name '<YourPolicyName>' -Policy $PolicyJson -Verbose

Discover more from VLDB

Subscribe now to keep reading and get access to the full archive.

Continue reading