Skip to content
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions dsc/examples/file_with_condition.dsc.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This example demonstrates how to create a file using the Windows PowerShell DSC extension.
// The file is created in the C:\DSC directory on the target machine.
// You should at least have the Bicep CLI v0.34.34 installed to run this example with experimental feature desiredStateConfiguration turned on.
// To run the second resource, you can add the --parameters '{"parameters":{"restartService":true}}' flag to the command line.

targetScope = 'desiredStateConfiguration'

@description('Set to true to ensure the service is running after the file creation.')
param restartService bool = false

resource powerShellAdapter 'Microsoft.Windows/WindowsPowerShell@2025-01-07' = {
name: 'Use Bicep to create file'
properties: {
resources: [
{
name: 'File'
type: 'PSDesiredStateConfiguration/File'
properties: {
Ensure: 'Present'
Type: 'File'
DestinationPath: 'C:\\DSC\\config.txt'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding C:, you should use the systemRoot() function to get the drive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if that was possible. I have created an issue on Bicep repository. Do you mind pulling in the example for now?

Contents: 'This file was created using Bicep extension from DSC.'
}
}
]
}
}

// Optionally ensure the service is running after the file creation
resource ensureServiceRunning 'PSDesiredStateConfiguration/Service@2025-01-07' = if (restartService) {
name: 'Ensure DSC service is running'
properties: {
Name: 'Spooler'
StartupType: 'Automatic'
State: 'Running'
}
}

Loading