1. Introduction of Windows PowerShell “Desired State Configuration”.
2. Installing Windows PowerShell 4.0 [Windows Management Framework 4.0].
3. Getting Started With Desired State Configuration: DSC Syntax.
4. Review of Desired State Configuration: The 3 easy steps.
5. Write your First Desired State Configuration Script using ROLE Resource.
6. Run your first "DSC" PowerShell Script.
7. Configuring Dependencies in "Desired State Configuration" script in PowerShell.
8. PowerShell and DSC : Using File Resource
14. Configure the Service to run under different account name in Service Resource.
I am hoping that you are already knows about "Windows Environment" variables, they are very helpful, I do use them heavily, they are very important piece in PowerShell scripts.
Today we are going to use the "Environment Resource" of the Windows PowerShell "Desired State Configuration" in our script.
The Syntax of the Windows Environment Resource is :
Let's get started.
This is the simplest "Desired State Configuration" script. In this script, we are setting a new "Windows Environment Variable" , named as "ServerRack", in this variable, I am manually storing the location of my server rack as a variable value.
I am sure , that in this script, I don't need to explain anything, this is very simple and straight forwarded script.
Configuration setEnvpath
{
Node 'Posh-Demo'
{
Environment serveRackInfo
{
Ensure = 'Present'
Name = "ServerRack"
Value = "Rack2 U9"
}
}
}
setEnvpath
Before running the script, lets' check the server and see if we have "ServerRack" Windows Environment variable set.
you can see that, currently there are no variable set yet.
The name of our script is "DSC_EnvironmentDemo.ps1" and the name of our "Desired State Configuration" Configuration is "setEnvpath".
Run the script, and it will export the MOF file.
Now, deploy the MOF file by using Start-DscConfiguration cmdlet.
Start-DscConfiguration -Path .\setEnvpath -Wait -Verbose
Our DSC script has run successfully.
Let's cross check it.
Note : Sometime, we may need to log-off or restart the system to check the Windows Environment after setup.
I am rebooting my server for a precaution sake.
My server is rebooted and after rebooting you can see in the below screenshot, that our Windows Environment variable ServerRack is set-up correctly and it is showing us the proper value.
That's all for now, will see you in my next blog post.
Thanks
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube” channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.