Is there a way to build a PowerShell desired state configuration (DSC) configuration file from a current system? Opposed of building the entire file from scratch?
Can a PowerShell DSC configuration file be created from a current system build
dscpowershell-v4.0
Related Solutions
The DSC Local Configuration Manager runs as the local SYSTEM account, not your user account. It therefore won't be able to access network resources unless it is given explicit permissions.
There are two possible situations. Either the share is on the same machine as the DSC configuration is being applied to (let's call this machine A) or the share is on a different machine (let's call this machine B).
If the share is on machine A, READ permissions need to be granted to the SYSTEM user. For example:
net share SomeShare=C:\SomeShare /GRANT:"NT AUTHORITY\SYSTEM",READ
If the share is on machine B, READ permissions need to be granted to the computer account of machine A. For example:
net share SomeShare=C:\SomeShare /GRANT:DOMAIN\MachineA$,READ
As you have said, you can do pretty much everything you would do with DSC, with straight powershell code.
But, DSC is all about configuration management.
Configuration management is about patterns and practices of using code and various systems to ensure a system is in a specific state. Ref 1 2
One important thing about Configuration management is idempotence. Meaning the code describing your system in the configuration management system will be checked and ran against your system periodically. Lots of basic scripts are not well designed, and will do the correct thing the first time you use it to configure a system, but the next time they will error, duplicate things and so on. Configuration management systems ideally will abstract away a large portion of the testing and state checking code you have to manually add in a script, to make your script idempotent.
Another important thing about DSC and many other configuration management systems is about making re-usable resources that actually do the work that can be shared with anyone and everyone in the world. In this way your actually 'configuration' should be just the few specific details that are specific to your environment. This also means you should need to write a lot less code, since you can re-use things that has been used and vetted by many other people.
I have included a few links above, but there are many good web sites you can find on the Internet about the theory of configuration management systems. The general theory applies to all configuration management systems (puppet, chef, dsc, ansible, etc) it is certainly worth learning, and worth using in most environments.
Best Answer
Not directly. You'd have to approach each resource you want to module independently.
For example, if you want to model the existing windows roles and features, you could script out something like
Each resource will be unique in how you want to identify those things you want to control.