├── .gitattributes ├── .gitignore ├── README.md ├── cHyper-V ├── DSCResources │ ├── cVMIPAddress │ │ ├── README.md │ │ ├── cVMIPAddress.psm1 │ │ ├── cVMIPAddress.schema.mof │ │ └── en-US │ │ │ └── cVMIPAddress.psd1 │ ├── cVMNetworkAdapter │ │ ├── Readme.md │ │ ├── cVMNetworkAdapter.psm1 │ │ ├── cVMNetworkAdapter.schema.mof │ │ └── en-US │ │ │ └── cVMNetworkAdapter.psd1 │ ├── cVMNetworkAdapterSettings │ │ ├── README.md │ │ ├── cVMNetworkAdapterSettings.psm1 │ │ ├── cVMNetworkAdapterSettings.schema.mof │ │ └── en-US │ │ │ └── cVMNetworkAdapterSettings.psd1 │ ├── cVMNetworkAdapterVlan │ │ ├── Readme.md │ │ ├── cVMNetworkAdapterVlan.psm1 │ │ ├── cVMNetworkAdapterVlan.schema.mof │ │ └── en-US │ │ │ └── cVMNetworkAdapterVlan.psd1 │ ├── cVMSwitch │ │ ├── README.md │ │ ├── cVMSwitch.psm1 │ │ ├── cVMSwitch.schema.mof │ │ └── en-US │ │ │ └── cVMSwitch.psd1 │ └── cWaitForVMGuestIntegration │ │ ├── README.md │ │ ├── cWaitForVMGuestIntegration.psm1 │ │ ├── cWaitForVMGuestIntegration.schema.mof │ │ └── en-US │ │ └── cWaitForVMGuestIntegration.psd1 ├── Examples │ ├── Resources │ │ ├── cVMIPAddress │ │ │ ├── ResetIPAddress.Example.ps1 │ │ │ └── SetIPAddress.Example.ps1 │ │ ├── cVMNetworkAdapter │ │ │ ├── CreateVMNetworkAdapterManagementOS.Example.ps1 │ │ │ ├── CreateVMNetworkAdapterMultipleManagementOS.Example.ps1 │ │ │ ├── CreateVMNetworkAdapterMultipleVM.Example.ps1 │ │ │ └── CreateVMNetworkAdapterMultipleVMMACAddress.Example.ps1 │ │ ├── cVMNetworkAdapterSettings │ │ │ ├── VMNetworkAdapterSettingsManagementOS.Example.ps1 │ │ │ ├── VMNetworkAdapterSettingsVMMultiple.Example.ps1 │ │ │ └── VMNetworkAdapterSettingsVMSimple.Example.ps1 │ │ ├── cVMNetworkAdapterVlan │ │ │ ├── VMNetworkAdapterVlanManagementOS.Example.ps1 │ │ │ ├── VMNetworkAdapterVlanMultipleManagementOS.Example.ps1 │ │ │ └── VMNetworkAdapterVlanMultipleVM.Example.ps1 │ │ ├── cVMSwitch │ │ │ ├── HostTeamSwitch.Example.ps1 │ │ │ ├── InternalSwitch.Example.ps1 │ │ │ ├── NetAdapterSwitch.Example.ps1 │ │ │ ├── PrivateSwitch.Example.ps1 │ │ │ └── SETTeamSwitch.Example.ps1 │ │ └── cWaitForVMIntegrationComponent │ │ │ ├── WaitForIntegrationComponentCustom.Example.ps1 │ │ │ └── WaitForIntegrationComponentDefault.Example.ps1 │ └── SwitchEmbeddedTeamingWithHostNetworkAdapter │ │ └── SETTeamWithHostNetworkAdapters.Example.ps1 ├── README.md └── cHyper-V.psd1 ├── cMMAgent ├── DSCResources │ ├── cMMAgentAD │ │ ├── cMMAgentAD.psm1 │ │ ├── cMMAgentAD.schema.mof │ │ └── en-US │ │ │ └── cMMAgentAD.psd1 │ ├── cMMAgentInstall │ │ ├── cMMAgentInstall.psd1 │ │ └── cMMAgentInstall.schema.psm1 │ ├── cMMAgentManagementGroups │ │ ├── cMMAgentManagementGroups.psm1 │ │ ├── cMMAgentManagementGroups.schema.mof │ │ └── en-US │ │ │ └── cMMAgentManagementGroups.psd1 │ ├── cMMAgentOpInsights │ │ ├── cMMAgentOpInsights.psm1 │ │ ├── cMMAgentOpInsights.schema.mof │ │ └── en-US │ │ │ └── cMMAgentOpInsights.psd1 │ ├── cMMAgentProxyCredential │ │ ├── cMMAgentProxyCredential.psm1 │ │ ├── cMMAgentProxyCredential.schema.mof │ │ └── en-US │ │ │ └── cMMAgentProxyCredential.psd1 │ └── cMMAgentProxyName │ │ ├── cMMAgentProxyName.psm1 │ │ ├── cMMAgentProxyName.schema.mof │ │ └── en-US │ │ └── cMMAgentProxyName.psd1 ├── README.md └── cMMAgent.psd1 ├── cMicrosoftAzureRecoveryServices ├── DSCResources │ ├── cMARSAgentInstall │ │ ├── cMARSAgentInstall.psd1 │ │ └── cMARSAgentInstall.schema.psm1 │ ├── cMARSEncryptionPhrase │ │ ├── cMARSEncryptionPhrase.psm1 │ │ ├── cMARSEncryptionPhrase.schema.mof │ │ └── en-US │ │ │ └── cMARSEncryptionPhrase.psd1 │ ├── cMARSProxy │ │ ├── cMARSProxy.psm1 │ │ ├── cMARSProxy.schema.mof │ │ └── en-US │ │ │ └── cMARSProxy.psd1 │ └── cMARSRegistration │ │ ├── cMARSRegistration.psm1 │ │ ├── cMARSRegistration.schema.mof │ │ └── en-US │ │ └── cMARSRegistration.psd1 ├── README.md └── cMicrosoftAzureRecoveryServices.psd1 ├── cWMIPermanentEvents ├── DSCResources │ ├── cWMIActiveScriptConsumer │ │ ├── cWMIActiveScriptConsumer.psm1 │ │ ├── cWMIActiveScriptConsumer.schema.mof │ │ └── en-US │ │ │ └── cWMIActiveScriptConsumer.psd1 │ ├── cWMICommandLineConsumer │ │ ├── cWMICommandLineConsumer.psm1 │ │ ├── cWMICommandLineConsumer.schema.mof │ │ └── en-US │ │ │ └── cWMICommandLineConsumer.psd1 │ ├── cWMIEventBinding │ │ ├── cWMIEventBinding.psm1 │ │ ├── cWMIEventBinding.schema.mof │ │ └── en-US │ │ │ └── cWMIEventBinding.psd1 │ ├── cWMIEventFilter │ │ ├── cWMIEventFilter.psm1 │ │ ├── cWMIEventFilter.schema.mof │ │ └── en-US │ │ │ └── cWMIEventFilter.psd1 │ ├── cWMIEventLogConsumer │ │ ├── cWMIEventLogConsumer.psm1 │ │ ├── cWMIEventLogConsumer.schema.mof │ │ └── en-US │ │ │ └── cWMIEventLogConsumer.psd1 │ ├── cWMILogFileConsumer │ │ ├── cWMILogFileConsumer.psm1 │ │ ├── cWMILogFileConsumer.schema.mof │ │ └── en-US │ │ │ └── cWMILogFileConsumer.psd1 │ └── cWMISMTPConsumer │ │ ├── cWMISMTPConsumer.psm1 │ │ ├── cWMISMTPConsumer.schema.mof │ │ └── en-US │ │ └── cWMISMTPConsumer.psd1 ├── README.md └── cWMIPermanentEvents.psd1 ├── cWindowsOS ├── DSCResources │ ├── cAutoAdminLogon │ │ ├── cAutoAdminLogon.psd1 │ │ └── cAutoAdminLogon.schema.psm1 │ ├── cDiskImage │ │ ├── cDiskImage.psm1 │ │ ├── cDiskImage.schema.mof │ │ └── en-US │ │ │ └── cDiskImage.psd1 │ └── cLoopBackCheck │ │ ├── cLoopBackCheck.psd1 │ │ └── cLoopBackCheck.schema.psm1 ├── README.md └── cWindowsOS.psd1 └── vscode ├── DSCResources ├── VSCodeExtension │ ├── VSCodeExtension.psm1 │ └── VSCodeExtension.schema.mof ├── VSCodeInsiderSetup │ └── VSCodeInsiderSetup.psm1 └── VSCodeSetup │ ├── VSCodeSetup.psm1 │ └── VSCodeSetup.schema.mof ├── README.md └── vscode.psd1 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DSCResources # 2 | ### Custom DSC resource modules by [PowerShell Magazine](http://www.powershellmagazine.com "PowerShell Magazine"). ### 3 | 4 | ---------- 5 | Custom DSC resource modules in this repository are packaged as different categories based on the functionality. 6 | 7 | - WMI Permanent Events Module ([cWMIPermanentEvents](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents)) 8 | - [cWMIEventFilter](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMIEventFilter) is used to create event filter instances for a given event query and event namespace. 9 | - [cWMIEventBinding](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMIEventBinding) is used to create binding between an event filter instance and an event consumer instance. 10 | - [cWMIEventLogConsumer](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMIEventLogConsumer) is used to create an instance of WMI Event Log consumer that writes to application log in response to an event. 11 | - [cWMILogFileConsumer](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMILogFileConsumer) is used to create an instance of WMI Log File that writes to a text log file in response to an event. 12 | - [cWMIActiveScriptConsumer](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMIActiveScriptConsumer) is used to create an instance of WMI Active Script Consumer that executes a specified VBScript file and VBScript text fragment in response to an event. 13 | - [cWMICommandLineConsumer](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMICommandLineConsumer) is used to create an instance of WMI CommandLine Consumer that executes a native application or a batch script in response to an event. 14 | - [cWMISMTPConsumer](https://github.com/rchaganti/DSCResources/tree/master/cWMIPermanentEvents/DSCResources/cWMISMTPConsumer) is used to create an instance of WMI SMTP Consumer that sends an email in response to an event. 15 | 16 | - Windows OS Miscellaneous Module ([cWindowsOS](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS)) 17 | - [cAutoAdminLogon](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS/DSCResources/cAutoAdminLogon) is used to add or remove auto administrator logon configuration. This is a composite resource. 18 | - [cLoopBackCheck](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS/DSCResources/cLoopBackCheck) is used to enable or disable Loopback Check registry setting for web servers such as SharePoint Front End servers. This is a composite resource. 19 | - c[DiskImage](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS/DSCResources/cDiskImage) is used to mount or dismount ISO images. 20 | 21 | - Microsoft Monitoring Agent ([cMMAgent](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent)) 22 | - [cMMAgentInstall](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent/DSCResources/cMMAgentInstall) is used to install Microsoft Monitoring Agent. 23 | - [cMMAgentProxyName](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent/DSCResources/cMMAgentProxyName) is used to add or remove the proxy URL for the Microsoft Monitoring Agent configuration. 24 | - [cMMAgentProxyCredential](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent/DSCResources/cMMAgentProxyCredential) is used to add, modify, or remove the credentials that need to be used to authenticate to a proxy configured using cMMAgentProxyName resource. 25 | - [cMMAgentOpInsights](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent/DSCResources/cMMAgentOpInsights) is used to enable or disable Azure Operational Insights within the Microsoft Monitoring Agent. This can also be used to update the WorkspaceID and WorkspaceKey for connecting to Azure Operational Insights. 26 | - [cMMAgentAD](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent/DSCResources/cMMAgentAD) is used to enable or disable Active Directory integration for the Microsoft Management Agent. By enabling AD integration, you can assign agent-managed computers to management groups. 27 | - [cMMAgentManagementGroups](https://github.com/rchaganti/DSCResources/tree/master/cMMAgent/DSCResources/cMMAgentManagementGroups) DSC resource can be used to add or remove management groups. You can use this resource to update the action account credentials for the management agent service. 28 | 29 | - Microsoft Azure Recovery Services (MARS) agent ([cMicrosoftRecoveryServicesAgent](https://github.com/rchaganti/DSCResources/tree/master/cMicrosoftAzureRecoveryServices)) 30 | - [cMARSAgentInstall](https://github.com/rchaganti/DSCResources/tree/master/cMicrosoftAzureRecoveryServices/DSCResources/cMARSAgentInstall) is used to install Microsoft Azure Recovery Services Agent. This is a composite resource that uses Package resource behind the scenes. 31 | - [cMARSProxy](https://github.com/rchaganti/DSCResources/tree/master/cMicrosoftAzureRecoveryServices/DSCResources/cMARSProxy) is used to configure the proxy settings for the MARS agent to connect to the Azure Backup Vault. 32 | - [cMARSRegistration](https://github.com/rchaganti/DSCResources/tree/master/cMicrosoftAzureRecoveryServices/DSCResources/cMARSRegistration) DSC resource should be used to register a target system with the Azure backup vault. 33 | - [cMARSEncryptionPhrase](https://github.com/rchaganti/DSCResources/tree/master/cMicrosoftAzureRecoveryServices/DSCResources/cMARSEncryptionPhrase) is used to configure the encryption settings for the MARS agent service. 34 | 35 | - Microsoft Hyper-V ([cHyper-V](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V)) 36 | - [cVMSwitch](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMSwitch) is used to create virtual machine switches. 37 | - [cVMNetworkAdapter](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMNetworkAdapter) is used to create VM network adapters to attach to either management OS or the virtual machines. 38 | - [cVMNetworkAdapterSettings](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMNetworkAdapterSettings) is used to configure VM network adapter settings such as bandwidth weights, port mirroring, DHCP guard, MAC address spoofing, etc. 39 | - [cVMNetworkAdapterVlan](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMNetworkAdapterVlan) is used to configure VLANs on virtual network adapters either in the management OS or virtual machines. 40 | - [cVMIPAddress](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMIPAddress) is used to inject IP Address into a virtual machine running on Hyper-V host. 41 | - [cWaitForVMGuestIntegration](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cWaitForVMGuestIntegration) is used to ensure that the VM integration components are running. This will be useful when you want to wait until a VM completes reboot and then perform an action. 42 | 43 | - Microsoft Visual Studio Code ([cHyper-V](https://github.com/rchaganti/DSCResources/tree/master/vscode)) 44 | - [vscodesetup](https://github.com/rchaganti/DSCResources/tree/master/vscode/DSCResources/vscodesetup) is used to install Visual Studio Code. 45 | - [vscodeextension](https://github.com/rchaganti/DSCResources/tree/master/vscode/DSCResources/vscodeextension) is used to install VS code extensions from the marketplace. 46 | 47 | These modules are available on [PowerShellGallery.com](https://www.powershellgallery.com). If you are using Windows PowerShell 5.0 or Packagemanagement module on PowerShell 4.0, you can install these modules using PowerShellGet module. 48 | 49 | Install-Module -Name cMMAgent 50 | Install-Module -Name cWindowsOS 51 | Install-Module -Name cWMIPermanentEvents 52 | Install-Module -Name cMicrosoftAzureRecoveryServices 53 | Install-Module -Name cHyper-V 54 | Install-Module -Name vscode -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMIPAddress/README.md: -------------------------------------------------------------------------------- 1 | #cVMIPAddress# 2 | This DSC resource helps in injecting IP addresses into a running VM on the Hyper-V host. This is especially useful in a bootstrap scenario where there is no DHCP server or unattended XML method to configure an IP Address inside the guest OS. I use this quite a lot for building VMs from template VHDx files. 3 | 4 | ![](http://i.imgur.com/S3UVP7F.png) 5 | 6 | The *Id* property is used to uniquely differentiate a VM network adapter that needs configuration. This is not a adapter property but a property that identifies the resource instance. This is a mandatory property. 7 | 8 | The *NetAdapterName* property identifies the VM network adapter. This is a mandatory property. 9 | 10 | The *VMName* property identifies the VM to which the network adapter is connected to. This is a mandatory property. 11 | 12 | The *IPAddress* property is the IP address that will be assigned to the network adapter. This is a mandatory property. If you want to remove a configured IP address or reset the IP address to DHCP, specify 'DHCP' as the value of this parameter. 13 | 14 | The *DefaultGateway* property is the default gateway address that will be assigned to the network adapter. 15 | 16 | The *Subnet* property is the subnet mask that will be assigned to the network adapter. 17 | 18 | The *DnsServer* property is the DNS Server address that will be assigned to the network adapter. 19 | 20 | Here are some examples that demonstrates how to use this resource. 21 | 22 | ##Assigning an IP address to a VM adapter## 23 | Configuration VMIPAddress 24 | { 25 | Import-DscResource -ModuleName cHyper-V -Name cVMIPAddress 26 | Import-DscResource -ModuleName PSDesiredStateConfiguration 27 | 28 | cVMIPAddress VMAdapter1IPAddress { 29 | Id = 'VMMgmt-NIC' 30 | NetAdapterName = 'VMMgmt-NIC' 31 | VMName = 'SQLVM01' 32 | IPAddress = '172.16.101.101' 33 | DefaultGateway = '172.16.101.1' 34 | Subnet = '255.255.255.0' 35 | DnsServer = '172.16.101.2' 36 | } 37 | } 38 | 39 | ##Removing an IP address assigned to a VM adapter## 40 | Configuration VMIPAddress 41 | { 42 | Import-DscResource -ModuleName cHyper-V -Name cVMIPAddress 43 | Import-DscResource -ModuleName PSDesiredStateConfiguration 44 | 45 | cVMIPAddress VMAdapter1IPAddress { 46 | Id = 'VMMgmt-NIC' 47 | NetAdapterName = 'VMMgmt-NIC' 48 | VMName = 'SQLVM01' 49 | IPAddress = 'DHCP' 50 | } 51 | } -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMIPAddress/cVMIPAddress.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMIPAddress/cVMIPAddress.psm1 -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMIPAddress/cVMIPAddress.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMIPAddress/cVMIPAddress.schema.mof -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMIPAddress/en-US/cVMIPAddress.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMIPAddress/en-US/cVMIPAddress.psd1 -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapter/Readme.md: -------------------------------------------------------------------------------- 1 | #Using cVMNetworkAdapter resource# 2 | This DSC resource can be used to attach network adapters to VM switches and add them to either management OS or virtual machines on the host. 3 | 4 | ![](http://i.imgur.com/KVSWBo8.png) 5 | 6 | The *Id* property is the unique key within this DSC resource. This property isn't related to any VM network adapter configuration but instead used as a way to uniquely identify each VM network adapter resource in a configuration. This property was introduced in an earlier version of this resource to ensure you can add netowrk adapter with the same name to different virtual machines. Make a note of that. **This won't still let you create two network adapters with the same name and attach them to same VM.** When configuring management OS or VM with multiple network adapters, you should still use unique name for each network adapter. *DO NOT USE A GUID AS AN ARGUMENT. ESPECIALLY, DYNAMICALLY GENERATED GUIDs* 7 | 8 | In the previous version of this DSC resource, *Name* property was the key property. Having *Name* as the key property prevented creating network adapters with the same name and attach them to different VMs. So, if you need to add a network adapter to the management OS, specify *VMName* as 'ManagementOS'. If the value of *VMName* property is not 'ManagementOS', it will be considered a Virtual Machine configuration and a network adapter will be added to VM on the Hyper-V host. 9 | 10 | The *Name* property and *SwitchName* property identify the name to be assigned to the VM network adapter and the name of the switch to attach to. 11 | 12 | If you want to assign a static MAC address to the VM network adapter, you can use the *MacAddress* property. Providing a value to this property sets the static MAC address on the VM network adapter. Removing this value will make it a dynamic MAC address. This can be used only with the virtual machine adapters and not management OS. 13 | 14 | The following examples demonstrate how to use this resource module. 15 | 16 | ## Create a management OS adapter on the Hyper-V host ## 17 | Configuration HostOSAdapter 18 | { 19 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 20 | Import-DscResource -ModuleName PSDesiredStateConfiguration 21 | 22 | cVMNetworkAdapter HostOSAdapter { 23 | Id = 'Management-NIC' 24 | Name = 'Management-NIC' 25 | SwitchName = 'SETSwitch' 26 | VMName = 'ManagementOS' 27 | Ensure = 'Present' 28 | } 29 | } 30 | 31 | ## Create multiple management OS adapters on the Hyper-V host ## 32 | Configuration HostOSAdapter 33 | { 34 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 35 | Import-DscResource -ModuleName PSDesiredStateConfiguration 36 | 37 | cVMNetworkAdapter ManagementAdapter { 38 | Id = 'Management-NIC' 39 | Name = 'Management-NIC' 40 | SwitchName = 'SETSwitch' 41 | VMName = 'ManagementOS' 42 | Ensure = 'Present' 43 | } 44 | 45 | cVMNetworkAdapter ClusterAdapter { 46 | Id = 'Cluster-NIC' 47 | Name = 'Cluster-NIC' 48 | SwitchName = 'SETSwitch' 49 | VMName = 'ManagementOS' 50 | Ensure = 'Present' 51 | } 52 | } 53 | 54 | ## Create multiple management OS adapters on the Hyper-V host ## 55 | Configuration VMAdapter 56 | { 57 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 58 | Import-DscResource -ModuleName PSDesiredStateConfiguration 59 | 60 | cVMNetworkAdapter MyVM01NIC { 61 | Id = 'MyVM01-NIC' 62 | Name = 'MyVM01-NIC' 63 | SwitchName = 'SETSwitch' 64 | VMName = 'MyVM01' 65 | Ensure = 'Present' 66 | } 67 | 68 | cVMNetworkAdapter MyVM02NIC { 69 | Id = 'MyVM02-NIC' 70 | Name = 'NetAdapter' 71 | SwitchName = 'SETSwitch' 72 | VMName = 'MyVM02' 73 | Ensure = 'Present' 74 | } 75 | 76 | #The following resource configuration shows that the different VMs can have network adapters with the same name. This is possible because Id is the key property and not Name. 77 | cVMNetworkAdapter MyVM03NIC { 78 | Id = 'MyVM03-NIC' 79 | Name = 'NetAdapter' 80 | SwitchName = 'SETSwitch' 81 | VMName = 'MyVM03' 82 | Ensure = 'Present' 83 | } 84 | } 85 | 86 | ##Create multiple management OS adapters with static MAC address on the Hyper-V host ## 87 | Configuration VMAdapter 88 | { 89 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 90 | Import-DscResource -ModuleName PSDesiredStateConfiguration 91 | 92 | cVMNetworkAdapter MyVM01NIC { 93 | Id = 'MyVM01-NIC' 94 | Name = 'MyVM01-NIC' 95 | SwitchName = 'SETSwitch' 96 | MacAddress = '001523be0c' 97 | VMName = 'MyVM01' 98 | Ensure = 'Present' 99 | } 100 | 101 | cVMNetworkAdapter MyVM02NIC { 102 | Id = 'MyVM02-NIC' 103 | Name = 'MyVM02-NIC' 104 | SwitchName = 'SETSwitch' 105 | MacAddress = '001523be0d' 106 | VMName = 'MyVM02' 107 | Ensure = 'Present' 108 | } 109 | } 110 | 111 | If you want to remove a network adapter either from the management OS or virtual machine, you need to set the *Ensure* property to *Absent*. -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapter/cVMNetworkAdapter.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMNetworkAdapter/cVMNetworkAdapter.schema.mof -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapter/en-US/cVMNetworkAdapter.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | VMNameAndManagementTogether=VMName cannot be provided when ManagementOS is set to True. 3 | MustProvideVMName=Must provide VMName parameter when ManagementOS is set to False. 4 | GetVMNetAdapter=Getting VM Network Adapter information. 5 | FoundVMNetAdapter=Found VM Network Adapter. 6 | NoVMNetAdapterFound=No VM Network Adapter found. 7 | StaticMacAddressChosen=Static MAC Address has been specified. 8 | StaticAddressDoesNotMatch=Staic MAC address on the VM Network Adapter does not match. 9 | ModifyVMNetAdapter=VM Network Adapter exists with different configuration. This will be modified. 10 | EnableDynamicMacAddress=VM Network Adapter exists but without Dynamic MAC address setting. 11 | EnableStaticMacAddress=VM Network Adapter exists but without static MAC address setting. 12 | PerformVMNetModify=Performing VM Network Adapter configuration changes. 13 | CannotChangeHostAdapterMacAddress=VM Network adapter in configuration is a host adapter. Its configuration cannot be modified. 14 | AddVMNetAdapter=Adding VM Network Adapter. 15 | RemoveVMNetAdapter=Removing VM Network Adapter. 16 | VMNetAdapterExistsNoActionNeeded=VM Network Adapter exists with requested configuration. No action needed. 17 | VMNetAdapterDoesNotExistShouldAdd=VM Network Adapter does not exist. It will be added. 18 | VMNetAdapterExistsShouldRemove=VM Network Adapter Exists. It will be removed. 19 | VMNetAdapterDoesNotExistNoActionNeeded=VM Network adapter does not exist. No action needed. 20 | StaticMacExists=StaicMacAddress configuration exists as desired. 21 | SwitchIsDifferent=Net Adapter is not connected to the requested switch. 22 | PerformSwitchConnect=Connecting VM Net adapter to the right switch. 23 | '@ 24 | -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapterSettings/README.md: -------------------------------------------------------------------------------- 1 | #Using cVMNetworkAdapterSettings resource# 2 | Once the VM network adapters are created, we can assign the bandwidth reservation or priority settings as needed. If we set the *MinimumBandwidthMode* to *Weight* during VM switch creation, we need to specify the percentage of bandwidth reservation for each adapter. We can this DSC resource for the purpose of updating the VM network adapter settings. This DSC resource can used for many other settings such as *DhcpGuard*, *RouterGuard*, *DeviceNaming*, and so on. 3 | 4 | ![](http://i.imgur.com/tZ1d4Fv.png) 5 | 6 | The *Id* property is mandatory as a unique key for the resource configuration. This identifies the right resource instance of the network adapter in the system. This was chosen as an input property because the VM network adapter name can be the same for multiple adapters connected to the same VM or management OS. 7 | 8 | The *Name* property identifies the name of the virtual network adapter. This is a required property. 9 | 10 | The *SwitchName* property is used to specify where (the VM switch) the network adapter is connected. This is a required property too. 11 | 12 | The *VMName* property is used to if a network adapter is connected to a VM or Management OS. If you need to add a network adapter to the management OS, specify *VMName* as 'ManagementOS'. If the value of *VMName* property is not 'ManagementOS', it will be considered a VM configuration and the network adapter attached to the VM will be configured for specified settings. 13 | 14 | The *MaximumBandwidth* property is used to specify the maximum bandwidth, in bits per second, for the VM network adapter. 15 | 16 | The *MinimumBandwidthAbsolute* specifies the minimum bandwidth, in bits per second, for the virtual network adapter. By default, these properties are set to zero which means those parameters within the network adapter are disabled. 17 | 18 | The *MinimumBandwidthWeight* specifies the minimum bandwidth, in terms of relative weight, for the virtual network adapter. The weight describes how much bandwidth to provide to the virtual network adapter relative to other virtual network adapters connected to the same virtual switch. 19 | 20 | If you want allow teaming of network adapters in the guest OS, you can set the *AllowTeaming* property to On. By default, this is set to *Off* and therefore disallows network teaming inside guest OS. 21 | 22 | Similar to this, there are other settings of a VM network adapter that you can configure. These properties include *DhcpGuard*, *MacAddressSpoofing*, *PortMirroring*, *RouterGuard*, *IeeePriorityTag*, *DeviceNaming*, and *VmqWeight*. These properties are self explanatory and are left to defaults for a VM network adapter. 23 | 24 | The following examples demonstrate how to use this DSC resource. 25 | 26 | ##Setting MinimumBandwidthWeight for a VM adapter in management OS## 27 | Configuration HostOSAdapterSettings 28 | { 29 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterSettings 30 | Import-DscResource -ModuleName PSDesiredStateConfiguration 31 | 32 | cVMNetworkAdapterSettings HostOSAdapterSettings { 33 | Id = 'Management-NIC' 34 | Name = 'Management-NIC' 35 | VMName = 'ManagementOS' 36 | SwitchName = 'SETSwitch' 37 | MinimumBandwidthWeight = 20 38 | } 39 | } 40 | 41 | ##Setting DHCP guard for a VM adapter connected to a VM## 42 | Configuration VMAdapterSettings 43 | { 44 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterSettings 45 | Import-DscResource -ModuleName PSDesiredStateConfiguration 46 | 47 | cVMNetworkAdapterSettings VMAdapterSettings { 48 | Id = 'Management-NIC' 49 | Name = 'Management-NIC' 50 | VMName = 'DHCPVM01' 51 | SwitchName = 'SETSwitch' 52 | DhcpGuard = 'On' 53 | } 54 | } 55 | 56 | ##Setting DHCPGuard and DeviceNaming on multiple VM network adapters connected to the same VM## 57 | Configuration VMAdapterSettings 58 | { 59 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterSettings 60 | Import-DscResource -ModuleName PSDesiredStateConfiguration 61 | 62 | cVMNetworkAdapterSettings VMAdapterSettings01 { 63 | Id = 'Management-NIC' 64 | Name = 'Management-NIC' 65 | VMName = 'DHCPVM01' 66 | SwitchName = 'SETSwitch' 67 | DhcpGuard = 'On' 68 | DeviceNaming = 'On' 69 | } 70 | 71 | cVMNetworkAdapterSettings VMAdapterSettings02 { 72 | Id = 'App-NIC' 73 | Name = 'App-NIC' 74 | VMName = 'DHCPVM01' 75 | SwitchName = 'SETSwitch' 76 | DeviceNaming = 'On' 77 | } 78 | } -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapterSettings/cVMNetworkAdapterSettings.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMNetworkAdapterSettings/cVMNetworkAdapterSettings.schema.mof -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapterSettings/en-US/cVMNetworkAdapterSettings.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | HyperVModuleNotFound=Hyper-V PowerShell Module not found. 3 | VMNameAndManagementTogether=VMName cannot be provided when ManagementOS is set to True. 4 | MustProvideVMName=Must provide VMName parameter when ManagementOS is set to False. 5 | GetVMNetAdapter=Getting VM Network Adapter information. 6 | FoundVMNetAdapter=Found VM Network Adapter. 7 | NoVMNetAdapterFound=No VM Network Adapter found. 8 | PerformVMNetModify=Performing VM Network Adapter configuration changes. 9 | VMNetAdapterExistsNoActionNeeded=VM Network Adapter exists with requested configuration. No action needed. 10 | VMNetAdapterDoesNotExist=VM Network adapter does not exist. 11 | VMNetAdapterExistsWithDifferentConfiguration=VM Network Adapter exists but different configuration. This will be fixed. 12 | '@ 13 | -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapterVlan/Readme.md: -------------------------------------------------------------------------------- 1 | #Using cVMNetworkAdapterVlan resource# 2 | This DSC resource can be used to assign VLAN information to a NIC that is created attached to either the management OS or a virtual machine. There are several possibilities here. 3 | 4 | ![](http://i.imgur.com/GMsXDyK.png) 5 | 6 | This resource has three mandatory properties. 7 | 8 | The *Id* property is a unique identifier to differentiate between multiple VMs containing the same network adapter name or same VM having multiple adapters named same. 9 | 10 | The *Name* property identifies the name of the network adapter for which the VLAN information needs to be configured. 11 | 12 | The *VMName* property identifies where the network adapter is connected. You can specify host OS by specifying a value *ManagementOS*. If the value of *VMName* property is not *ManagementOS*, it will be considered a Virtual Machine configuration and the network adapter attached to the VM will be configured for VLAN settings. 13 | 14 | The *AdapterMode* property specifies the operation mode of the adapter and is by default set to *Untagged* which means there is no VLAN configuration. The possible and valid values for this property are *Untagged*, *Access*, *Trunk*, *Community*, *Isolated*, and *Promiscuous*. Each of these modes have a corresponding VLAN property that is mandatory. 15 | 16 | If you set the *AdapterMode* property to *Access*, then it is mandatory to provide *VlanId* property. 17 | 18 | If you set the *AdapterMode* to *Trunk*, the *NativeVlanId* property must be specified. 19 | 20 | The following examples demonstrate how to use this DSC resource. 21 | 22 | ##Simple Management OS NIC VLAN configuration for Access VLAN## 23 | 24 | Configuration HostOSAdapterVlan 25 | { 26 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterVlan 27 | Import-DscResource -ModuleName PSDesiredStateConfiguration 28 | 29 | cVMNetworkAdapterVlan HostOSAdapterVlan { 30 | Id = 'Management-NIC' 31 | Name = 'Management-NIC' 32 | VMName = 'ManagementOS' 33 | AdapterMode = 'Access' 34 | VlanId = 10 35 | } 36 | } 37 | 38 | ##Multiple Management OS NIC VLAN configuration for Access and Untagged VLAN## 39 | 40 | Configuration HostOSAdapterVlan 41 | { 42 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterVlan 43 | Import-DscResource -ModuleName PSDesiredStateConfiguration 44 | 45 | cVMNetworkAdapterVlan HostOSAdapterVlan { 46 | Id = 'Management-NIC' 47 | Name = 'Management-NIC' 48 | VMName = 'ManagementOS' 49 | AdapterMode = 'Access' 50 | VlanId = 10 51 | } 52 | 53 | cVMNetworkAdapterVlan ClusterAdapterVlan { 54 | Id = 'Cluster-NIC' 55 | Name = 'Cluster-NIC' 56 | VMName = 'ManagementOS' 57 | AdapterMode = 'Access' 58 | VlanId = 20 59 | } 60 | 61 | #The following configuration removes any VLAN setting, if present. 62 | cVMNetworkAdapterVlan JustAnotherAdapterVlan { 63 | Id = 'JustAnother-NIC' 64 | Name = 'JustAnother-NIC' 65 | VMName = 'ManagementOS' 66 | AdapterMode = 'Untagged' 67 | } 68 | } 69 | 70 | In the above example, setting the *AdapterMode* to *Untagged* removes any VLAN configuration on the NIC, if present. By default, all VM network adapters will be in Untagged mode. 71 | 72 | ##Multiple Management OS NIC VLAN configuration for Access and Untagged VLAN## 73 | 74 | Configuration HostOSAdapterVlan 75 | { 76 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterVlan 77 | Import-DscResource -ModuleName PSDesiredStateConfiguration 78 | 79 | cVMNetworkAdapterVlan VMMgmtAdapterVlan { 80 | Id = 'VMManagement-NIC' 81 | Name = 'VMManagement-NIC' 82 | VMName = 'SQLVM01' 83 | AdapterMode = 'Access' 84 | VlanId = 10 85 | } 86 | 87 | cVMNetworkAdapterVlan VMiSCSIAdapterVlan { 88 | Id = 'VMiSCSI-NIC' 89 | Name = 'VMiSCSI-NIC' 90 | VMName = 'SQLVM01' 91 | AdapterMode = 'Untagged' 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapterVlan/cVMNetworkAdapterVlan.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMNetworkAdapterVlan/cVMNetworkAdapterVlan.schema.mof -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMNetworkAdapterVlan/en-US/cVMNetworkAdapterVlan.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | HyperVModuleNotFound=Hyper-V PowerShell Module not found. 3 | VMNameAndManagementTogether=VMName cannot be provided when ManagementOS is set to True. 4 | MustProvideVMName=Must provide VMName parameter when ManagementOS is set to False. 5 | GetVMNetAdapter=Getting VM Network Adapter information. 6 | FoundVMNetAdapter=Found VM Network Adapter. 7 | NoVMNetAdapterFound=No VM Network Adapter found. 8 | VMNetAdapterDoesNotExist=VM Network Adapter does not exist. 9 | PerformVMVlanSet=Perfoming VM Network Adapter VLAN setting configuration. 10 | IgnoreVlan=Ignoring VLAN configuration when the opeartion mode chosen is Untagged. 11 | VlanIdRequiredInAccess=VlanId must be specified when chosen operation mode is Access. 12 | MustProvideNativeVlanId=NativeVlanId must be specified when chosen operation mode is Trunk. 13 | PrimaryVlanIdRequired=PrimaryVlanId is required when the chosen operation mode is Community or Isolated or Promiscuous. 14 | AccessVlanMustChange=VlanId in Access mode is different. It will be changed. 15 | AdaptersExistsWithVlan=VM Network adapter exists with required VLAN configuration. 16 | NativeVlanMustChange=NativeVlanId in Trunk mode is different and it wil be changed. 17 | AllowedVlanListMustChange=AllowedVlanIdList is different in trunk mode. It will be changed. 18 | PrimaryVlanMustChange=PrimaryVlanId is different and must be changed. 19 | SecondaryVlanMustChange=SecondaryVlanId is different and must be changed. 20 | SecondaryVlanListMustChange=SecondaryVlanIdList is different and must be changed. 21 | AdapterExistsWithDifferentVlanMode=VM Network adapter exists with different Vlan configuration. It will be fixed. 22 | '@ 23 | -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMSwitch/README.md: -------------------------------------------------------------------------------- 1 | #cVMSwitch PowerShell DSC Resource# 2 | This resource module is a fork from Microsoft's xHyper-V resource module. I have added the capability to manage bandwidth settings of the VM switch and to deploy Switch Embedded teaming in Windows Server 2016. 3 | 4 | ![](http://i.imgur.com/odgNbD3.png) 5 | 6 | When using this DSC resource, the *Name* and *Type* are mandatory properties where *Name* is the unique key properties. 7 | 8 | The *AllowManagementOS* property can be used to add a VM network adapter attached to the VM switch we are creating in the management OS. 9 | 10 | The *EnableIoV* property lets us enable SR-IOV capability on the VM switch. 11 | 12 | The *MinimumBandwidthMode* and *EnableIoV* properties are mutually exclusive. We cannot configure both at the same time. 13 | 14 | The *MinimumBandwidthMode* property can be used to configure a converged network switch on Hyper-V. 15 | 16 | The *NetAdapterName* parameter is used when creating a VM switch of *External* type. If you pass multiple adapter names to this parameter, a switch embedded team will be provisioned. You can specify a comma-separated list of physical network adapters. Although, it is technically possible to create a SET team with just one adapter, from a design point of view, I simplified this by putting a constraint on at least two adapters to create a SET team. 17 | 18 | The *LoadBalancingAlgorigthm* specifies the LB mode for the SET team. At the time of writing this resource module, SET supports only *SwitchIndepedent* load balancing algorithm. This applies only when multiple network adapters are specified. 19 | 20 | The *TeamingMode* can be set of either *HyperVPort* or *Dynamic*. The default is *Dynamic*. This applies only when multiple network adapters are specified. 21 | 22 | The following examples demonstrate how to use this resource module. 23 | ### Create a simple VM Switch from a native network team on the Hyper-V host ### 24 | Configuration SimpleHostTeamvSwitch 25 | { 26 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 27 | Import-DscResource -ModuleName PSDesiredStateConfiguration 28 | 29 | cVMSwitch HostSwitch { 30 | Name = 'HostSwitch' 31 | Type = 'External' 32 | AllowManagementOS = $true 33 | MinimumBandwidthMode = 'Weight' 34 | NetAdapterName = 'HostTeam' 35 | Ensure = 'Present' 36 | } 37 | } 38 | 39 | ## Create a simple VM Switch using a network adapter on the Hyper-V host ## 40 | Configuration SimpleNetAdaptervSwitch 41 | { 42 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 43 | Import-DscResource -ModuleName PSDesiredStateConfiguration 44 | 45 | cVMSwitch HostSwitch { 46 | Name = 'HostSwitch' 47 | Type = 'External' 48 | AllowManagementOS = $true 49 | NetAdapterName = 'NIC1' 50 | Ensure = 'Present' 51 | } 52 | } 53 | 54 | ## Create a Switch Embedded Team switch using four network adapters on the Hyper-V host ## 55 | Configuration SETTeamSwitch 56 | { 57 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 58 | Import-DscResource -ModuleName PSDesiredStateConfiguration 59 | 60 | cVMSwitch HostSwitch { 61 | Name = 'HostSwitch' 62 | Type = 'External' 63 | AllowManagementOS = $true 64 | MinimumBandwidthMode = 'Weight' 65 | TeamingMode = 'SwitchIndependent' 66 | LoadBalancingAlgorithm = 'HyperVPort' 67 | NetAdapterName = 'NIC1','NIC2','NIC3','NIC4' 68 | Ensure = 'Present' 69 | } 70 | } 71 | 72 | ## Create a private VM switch on the Hyper-V host ## 73 | Configuration PrivateSwitch 74 | { 75 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 76 | Import-DscResource -ModuleName PSDesiredStateConfiguration 77 | 78 | cVMSwitch HostSwitch { 79 | Name = 'HostSwitch' 80 | Type = 'Private' 81 | Ensure = 'Present' 82 | } 83 | } 84 | 85 | ## Create a internal VM switch on the Hyper-V host ## 86 | Configuration InternalSwitch 87 | { 88 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 89 | Import-DscResource -ModuleName PSDesiredStateConfiguration 90 | 91 | cVMSwitch HostSwitch { 92 | Name = 'HostSwitch' 93 | Type = 'Internal' 94 | Ensure = 'Present' 95 | } 96 | } 97 | 98 | To remove any of these switches, you can simply switch the *Ensure* property to *Absent*. -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMSwitch/cVMSwitch.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cVMSwitch/cVMSwitch.schema.mof -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cVMSwitch/en-US/cVMSwitch.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | HyperVModuleNotFound=Hyper-V Module was not found on this system. 3 | FoundSetTeam=VM Switch is an embedded team. 4 | NoSwitchFound=No VM Switch provided details found. 5 | FoundSwitch=Found a VM switch with provided details. 6 | FoundExternalSwitch=VM switch is an external switch. 7 | InternalPrivateWithAllowManagementOS=AllowManagementOS cannot be specified when the switch type is set to Internal or Private. 8 | NetAdapterNameForExternal=For external switch type, NetAdapterName must be specified. 9 | NoNetAdapterInternalPrivate=For Internal or Private switch type, NetAdapterName should not be specified. 10 | NoSETForInternalPrivate=In this release, TeamingMode and/or LoadBalancingAlgorithm can be set only when Switch type is external. 11 | IOVPDTogether=EnablePacketDirect and EnableIoV cannot specified together. 12 | IOVMBwithSET=EnableIOV and SET cannot be cannot specified when using MinimumBandwidthMode. 13 | PDMBwithSET=EnablePacketDirect and EnableEmbeddedTeaming cannot specified when using MinimumBandwidthMode. 14 | FoundIntORPvtSwitch=Found a VM switch of type {0} 15 | NeedASET=Multiple Network Adapters specified. We need a SET Team. 16 | ReCreateSET=Switch found is not a SET Team. We need to recreate it. 17 | CreateSwitch=Creating a new VM switch. 18 | SETFoundCheckNetAdapter=SET Team found. Checking network adapter members. 19 | SETMembersDontMatch=SET Team members not matching. We need to update the VM Switch. 20 | UpdateSETTeam=Updating SET Team. 21 | NeedANormalSwitch=A SET team was found. We need a normal switch. 22 | RemovingSwitch=Removing VM switch. 23 | UpdateSwitch=Updating VM Switch properties. 24 | WeShouldNeverReachHere=VM Switch is either internal or private. The control should never reach here. 25 | LBDifferent=Load Balancing mode different. 26 | TeamingDifferent=Teaming mode is different. 27 | NetAdapterDifferent=Network adapter did not match. 28 | AllowMgmtOSDifferent=Allow Management OS property does not match. 29 | EPDCannotChange=PacketDirect is not enabled and this configuration cannot be updated once switch is created unless we destroy and re-create. Consider doing this manually. 30 | IOVCannotChange=IOV is not enabled and this configuration cannot be updated once switch is created unless we destroy and re-create. Consider doing this manually. 31 | MBCannotChange=MinimumBandwidthMode is not matching and this configuration cannot be updated once switch is created unless we destroy and re-create. Consider doing this manually. 32 | SwitchExistsNoAction=Switch exists. No action needed. 33 | SwitchExistsItShouldnot=Switch exists while it should not. 34 | SwitchShouldExist=Switch does not exist while it should. 35 | SwitchDoesNotExistNoAction=Switch does not exist. No action needed. 36 | '@ 37 | -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cWaitForVMGuestIntegration/README.md: -------------------------------------------------------------------------------- 1 | #cWaitForVMGuestIntegration# 2 | This DSC resource is especially helpful when a VM resource configuration requires that the VM integration components are up and running. You can use this resource to wait for the guest integration components. For example, to be able to inject an IP address (using cVMIPAddress DSC resource) into a newly created Windows VM, the VM should have integration components installed and running. In such a configuration scenario, you can use this resource to wait until the integration components change into running state. 3 | 4 | ![](http://i.imgur.com/rtiyk4B.png) 5 | 6 | The *Id* property is an instance identifier and key property in the resource configuration. This does not identify any VM property instead provides a way to wait for the integration components of that VM multiple times in a single configuration document. 7 | 8 | The *VMName* property identifies the virtual machine in which the guest integration components should be in running state. This is a mandatory property. 9 | 10 | The *RetryCount* property identifies how many times the resource should try to test for guest integration component state. Default value is 5. This is an optional property. 11 | 12 | The *RetryIntervalSec* property identifies interval (in seconds) between retries. Default Value is 10 seconds. This is an optional property. 13 | 14 | Here are some examples that demonstrates how to use this resource. 15 | 16 | ##Wait For VM IC with default retry values## 17 | Configuration WaitForIC 18 | { 19 | Import-DscResource -Name cWaitForVMGuestIntegration -ModuleName cHyper-V 20 | 21 | cWaitForVMGuestIntegration VM01 22 | { 23 | Id = 'VM01-IC01' 24 | VMName = 'VM01' 25 | } 26 | } 27 | 28 | ##Wait for VM IC with custom retry values## 29 | Configuration WaitForIC 30 | { 31 | Import-DscResource -Name cWaitForVMGuestIntegration -ModuleName cHyper-V 32 | 33 | cWaitForVMGuestIntegration VM01 34 | { 35 | Id = 'VM01-IC01' 36 | VMName = 'VM01' 37 | RetryIntervalSec = 20 38 | RetryCount = 10 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cWaitForVMGuestIntegration/cWaitForVMGuestIntegration.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cWaitForVMGuestIntegration/cWaitForVMGuestIntegration.psm1 -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cWaitForVMGuestIntegration/cWaitForVMGuestIntegration.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cWaitForVMGuestIntegration/cWaitForVMGuestIntegration.schema.mof -------------------------------------------------------------------------------- /cHyper-V/DSCResources/cWaitForVMGuestIntegration/en-US/cWaitForVMGuestIntegration.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/DSCResources/cWaitForVMGuestIntegration/en-US/cWaitForVMGuestIntegration.psd1 -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMIPAddress/ResetIPAddress.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration VMIPAddress 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMIPAddress 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMIPAddress VMAdapter1IPAddress { 7 | Id = 'VMMgmt-NIC' 8 | NetAdapterName = 'VMMgmt-NIC' 9 | VMName = 'SQLVM01' 10 | IPAddress = 'DHCP' 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMIPAddress/SetIPAddress.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration VMIPAddress 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMIPAddress 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMIPAddress VMAdapter1IPAddress { 7 | Id = 'VMMgmt-NIC' 8 | NetAdapterName = 'VMMgmt-NIC' 9 | VMName = 'SQLVM01' 10 | IPAddress = '172.16.101.101' 11 | DefaultGateway = '172.16.101.1' 12 | Subnet = '255.255.255.0' 13 | DnsServer = '172.16.101.2' 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapter/CreateVMNetworkAdapterManagementOS.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration HostOSAdapter 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapter HostOSAdapter { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | SwitchName = 'SETSwitch' 10 | VMName = 'ManagementOS' 11 | Ensure = 'Present' 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapter/CreateVMNetworkAdapterMultipleManagementOS.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration HostOSAdapter 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapter ManagementAdapter { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | SwitchName = 'SETSwitch' 10 | VMName = 'ManagementOS' 11 | Ensure = 'Present' 12 | } 13 | 14 | cVMNetworkAdapter ClusterAdapter { 15 | Id = 'Cluster-NIC' 16 | Name = 'Cluster-NIC' 17 | SwitchName = 'SETSwitch' 18 | VMName = 'ManagementOS' 19 | Ensure = 'Present' 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapter/CreateVMNetworkAdapterMultipleVM.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration VMAdapter 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapter MyVM01NIC { 7 | Id = 'MyVM01-NIC' 8 | Name = 'MyVM01-NIC' 9 | SwitchName = 'SETSwitch' 10 | VMName = 'MyVM01' 11 | Ensure = 'Present' 12 | } 13 | 14 | cVMNetworkAdapter MyVM02NIC { 15 | Id = 'MyVM02-NIC' 16 | Name = 'NetAdapter' 17 | SwitchName = 'SETSwitch' 18 | VMName = 'MyVM02' 19 | Ensure = 'Present' 20 | } 21 | 22 | cVMNetworkAdapter MyVM03NIC { 23 | Id = 'MyVM03-NIC' 24 | Name = 'NetAdapter' 25 | SwitchName = 'SETSwitch' 26 | VMName = 'MyVM03' 27 | Ensure = 'Present' 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapter/CreateVMNetworkAdapterMultipleVMMACAddress.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration VMAdapter 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapter 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapter MyVM01NIC { 7 | Id = 'MyVM01-NIC' 8 | Name = 'MyVM01-NIC' 9 | SwitchName = 'SETSwitch' 10 | MacAddress = '001523be0c' 11 | VMName = 'MyVM01' 12 | Ensure = 'Present' 13 | } 14 | 15 | cVMNetworkAdapter MyVM02NIC { 16 | Id = 'MyVM02-NIC' 17 | Name = 'MyVM02-NIC' 18 | SwitchName = 'SETSwitch' 19 | MacAddress = '001523be0d' 20 | VMName = 'MyVM02' 21 | Ensure = 'Present' 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapterSettings/VMNetworkAdapterSettingsManagementOS.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration HostOSAdapterSettings 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterSettings 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapterSettings HostOSAdapterSettings { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | VMName = 'ManagementOS' 10 | SwitchName = 'SETSwitch' 11 | MinimumBandwidthWeight = 20 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapterSettings/VMNetworkAdapterSettingsVMMultiple.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration VMAdapterSettings 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterSettings 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapterSettings VMAdapterSettings01 { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | VMName = 'DHCPVM01' 10 | SwitchName = 'SETSwitch' 11 | DhcpGuard = 'On' 12 | DeviceNaming = 'On' 13 | } 14 | 15 | cVMNetworkAdapterSettings VMAdapterSettings02 { 16 | Id = 'App-NIC' 17 | Name = 'App-NIC' 18 | VMName = 'DHCPVM01' 19 | SwitchName = 'SETSwitch' 20 | DeviceNaming = 'On' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapterSettings/VMNetworkAdapterSettingsVMSimple.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration VMAdapterSettings 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterSettings 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapterSettings VMAdapterSettings { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | VMName = 'DHCPVM01' 10 | SwitchName = 'SETSwitch' 11 | DhcpGuard = 'On' 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapterVlan/VMNetworkAdapterVlanManagementOS.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration HostOSAdapterVlan 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterVlan 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapterVlan HostOSAdapterVlan { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | VMName = 'ManagementOS' 10 | AdapterMode = 'Access' 11 | VlanId = 10 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapterVlan/VMNetworkAdapterVlanMultipleManagementOS.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration HostOSAdapterVlan 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterVlan 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapterVlan HostOSAdapterVlan { 7 | Id = 'Management-NIC' 8 | Name = 'Management-NIC' 9 | VMName = 'ManagementOS' 10 | AdapterMode = 'Access' 11 | VlanId = 10 12 | } 13 | 14 | cVMNetworkAdapterVlan ClusterAdapterVlan { 15 | Id = 'Cluster-NIC' 16 | Name = 'Cluster-NIC' 17 | VMName = 'ManagementOS' 18 | AdapterMode = 'Access' 19 | VlanId = 20 20 | } 21 | 22 | #The following configuration removes any VLAN setting, if present. 23 | cVMNetworkAdapterVlan JustAnotherAdapterVlan { 24 | Id = 'JustAnother-NIC' 25 | Name = 'JustAnother-NIC' 26 | VMName = 'ManagementOS' 27 | AdapterMode = 'Untagged' 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMNetworkAdapterVlan/VMNetworkAdapterVlanMultipleVM.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration HostOSAdapterVlan 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMNetworkAdapterVlan 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMNetworkAdapterVlan VMMgmtAdapterVlan { 7 | Id = 'VMManagement-NIC' 8 | Name = 'VMManagement-NIC' 9 | VMName = 'SQLVM01' 10 | AdapterMode = 'Access' 11 | VlanId = 10 12 | } 13 | 14 | cVMNetworkAdapterVlan VMiSCSIAdapterVlan { 15 | Id = 'VMiSCSI-NIC' 16 | Name = 'VMiSCSI-NIC' 17 | VMName = 'SQLVM01' 18 | AdapterMode = 'Untagged' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMSwitch/HostTeamSwitch.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration SimpleHostTeamvSwitch 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMSwitch HostSwitch { 7 | Name = 'HostSwitch' 8 | Type = 'External' 9 | AllowManagementOS = $true 10 | MinimumBandwidthMode = 'Weight' 11 | NetAdapterName = 'HostTeam' 12 | Ensure = 'Present' 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMSwitch/InternalSwitch.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration InternalSwitch 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMSwitch HostSwitch { 7 | Name = 'HostSwitch' 8 | Type = 'Internal' 9 | Ensure = 'Present' 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMSwitch/NetAdapterSwitch.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration SimpleNetAdaptervSwitch 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMSwitch HostSwitch { 7 | Name = 'HostSwitch' 8 | Type = 'External' 9 | AllowManagementOS = $true 10 | NetAdapterName = 'NIC1' 11 | Ensure = 'Present' 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMSwitch/PrivateSwitch.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration PrivateSwitch 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMSwitch HostSwitch { 7 | Name = 'HostSwitch' 8 | Type = 'Private' 9 | Ensure = 'Present' 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cVMSwitch/SETTeamSwitch.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration SETTeamSwitch 2 | { 3 | Import-DscResource -ModuleName cHyper-V -Name cVMSwitch 4 | Import-DscResource -ModuleName PSDesiredStateConfiguration 5 | 6 | cVMSwitch HostSwitch { 7 | Name = 'HostSwitch' 8 | Type = 'External' 9 | AllowManagementOS = $true 10 | MinimumBandwidthMode = 'Weight' 11 | TeamingMode = 'SwitchIndependent' 12 | LoadBalancingAlgorithm = 'HyperVPort' 13 | NetAdapterName = 'NIC1','NIC2','NIC3','NIC4' 14 | Ensure = 'Present' 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cWaitForVMIntegrationComponent/WaitForIntegrationComponentCustom.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration WaitForIC 2 | { 3 | Import-DscResource -Name cWaitForVMGuestIntegration -ModuleName cHyper-V 4 | 5 | cWaitForVMGuestIntegration VM01 6 | { 7 | Id = 'VM01-IC01' 8 | VMName = 'VM01' 9 | RetryIntervalSec = 20 10 | RetryCount = 10 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cHyper-V/Examples/Resources/cWaitForVMIntegrationComponent/WaitForIntegrationComponentDefault.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration WaitForIC 2 | { 3 | Import-DscResource -Name cWaitForVMGuestIntegration -ModuleName cHyper-V 4 | 5 | cWaitForVMGuestIntegration VM01 6 | { 7 | Id = 'VM01-IC01' 8 | VMName = 'VM01' 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /cHyper-V/Examples/SwitchEmbeddedTeamingWithHostNetworkAdapter/SETTeamWithHostNetworkAdapters.Example.ps1: -------------------------------------------------------------------------------- 1 | Configuration SETTeam 2 | { 3 | param ( 4 | [String] $SwitchName, 5 | [String[]] $NetAdapterName, 6 | [Int] $ManagementVlan, 7 | [Int] $ManagementBandwidthWeight, 8 | [String] $ClusterAdapterName, 9 | [Int] $ClusterVlan, 10 | [Int] $ClusterBandwidthWeight, 11 | [String] $LiveMigrationAdapterName, 12 | [Int] $LiveMigrationVlan, 13 | [Int] $LiveMigrationBandwidthWeight 14 | ) 15 | Import-DscResource -ModuleName cHyper-V 16 | 17 | cVMSwitch $SwitchName 18 | { 19 | Name = $SwitchName 20 | NetAdapterName = $NetAdapterName 21 | Type = 'External' 22 | MinimumBandwidthMode = 'Weight' 23 | TeamingMode = 'SwitchIndependent' 24 | LoadBalancingAlgorithm = 'Dynamic' 25 | Ensure = 'Present' 26 | } 27 | 28 | cVMNetworkAdapterVlan $SwitchName 29 | { 30 | Id = 'Mgmt-NIC' 31 | Name = $SwitchName 32 | AdapterMode = 'Access' 33 | VlanId = $ManagementVlan 34 | VMName = 'ManagementOS' 35 | DependsOn = "[cVMSwitch]$SwitchName" 36 | } 37 | 38 | cVMNetworkAdapterSettings $SwitchName 39 | { 40 | Id = 'Mgmt-NIC' 41 | Name = $SwitchName 42 | VMName = 'ManagementOS' 43 | SwitchName = $SwitchName 44 | MinimumBandwidthWeight = $ManagementBandwidthWeight 45 | DependsOn = "[cVMSwitch]$SwitchName" 46 | } 47 | 48 | cVMNetworkAdapter $ClusterAdapterName 49 | { 50 | Id = 'Cluster-NIC' 51 | Name = $ClusterAdapterName 52 | VMName = 'ManagementOS' 53 | SwitchName = $SwitchName 54 | DependsOn = "[cVMSwitch]$SwitchName" 55 | } 56 | 57 | cVMNetworkAdapterVlan $ClusterAdapterName 58 | { 59 | Id = 'Cluster-NIC' 60 | Name = $ClusterAdapterName 61 | AdapterMode = 'Access' 62 | VlanId = $ClusterVlan 63 | VMName = 'ManagementOS' 64 | DependsOn = "[cVMNetworkAdapter]$ClusterAdapterName" 65 | } 66 | 67 | cVMNetworkAdapterSettings $ClusterAdapterName 68 | { 69 | Id = 'Cluster-NIC' 70 | Name = $ClusterAdapterName 71 | VMName = 'ManagementOS' 72 | SwitchName = $SwitchName 73 | MinimumBandwidthWeight = $ClusterBandwidthWeight 74 | DependsOn = "[cVMNetworkAdapter]$ClusterAdapterName" 75 | } 76 | 77 | cVMNetworkAdapter $LiveMigrationAdapterName 78 | { 79 | Id = 'LM-NIC' 80 | Name = $LiveMigrationAdapterName 81 | VMName = 'ManagementOS' 82 | SwitchName = $SwitchName 83 | DependsOn = "[cVMSwitch]$SwitchName" 84 | } 85 | 86 | cVMNetworkAdapterVlan $LiveMigrationAdapterName 87 | { 88 | Id = 'LM-NIC' 89 | Name = $LiveMigrationAdapterName 90 | AdapterMode = 'Access' 91 | VlanId = $LiveMigrationVlan 92 | VMName = 'ManagementOS' 93 | DependsOn = "[cVMNetworkAdapter]$LiveMigrationAdapterName" 94 | } 95 | 96 | cVMNetworkAdapterSettings $LiveMigrationAdapterName 97 | { 98 | Id = 'LM-NIC' 99 | Name = $LiveMigrationAdapterName 100 | VMName = 'ManagementOS' 101 | SwitchName = $SwitchName 102 | MinimumBandwidthWeight = $LiveMigrationBandwidthWeight 103 | DependsOn = "[cVMNetworkAdapter]$LiveMigrationAdapterName" 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /cHyper-V/README.md: -------------------------------------------------------------------------------- 1 | # DSCResources # 2 | ### Custom DSC resource module for Microsoft Hyper-V Networking by [PowerShell Magazine](http://www.powershellmagazine.com "PowerShell Magazine"). ### 3 | ---------- 4 | 5 | ### This release (3.0.0.0) removed the cSwitchEmbededTeaming and cNATSwitch from this resource module. The functionality for creating SET team is now a part of cVMSwitch and cNatSwitch will go to xNetworking soon! ### 6 | 7 | Microsoft Hyper-V DSC resource module contains a set of resources for managing Hyper-V management OS and guest networking. 8 | 9 | - [cVMSwitch](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMSwitch) is used to create virtual machine switches. 10 | - [cVMNetworkAdapter](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMNetworkAdapter) is used to create VM network adapters to attach to either management OS or the virtual machines. 11 | - [cVMNetworkAdapterSettings](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMNetworkAdapterSettings) is used to configure VM network adapter settings such as bandwidth weights, port mirroring, DHCP guard, MAC address spoofing, etc. 12 | - [cVMNetworkAdapterVlan](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMNetworkAdapterVlan) is used to configure VLANs on virtual network adapters either in the management OS or virtual machines. 13 | - [cVMIPAddress](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cVMIPAddress) is used to inject IP Address into a virtual machine running on Hyper-V host. 14 | - [cWaitForVMGuestIntegration](https://github.com/rchaganti/DSCResources/tree/master/cHyper-V/DSCResources/cWaitForVMGuestIntegration) is used to ensure that the VM integration components are running. This will be useful when you want to wait until a VM completes reboot and then perform an action. 15 | 16 | Note that before using any of the custom resources, you must either import the individual resources or the entire module containing these resources. You can do this using the Import-DscResource cmdlet. 17 | 18 | Note: For documentation of each of these resources, visit the resource page. -------------------------------------------------------------------------------- /cHyper-V/cHyper-V.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cHyper-V/cHyper-V.psd1 -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentAD/cMMAgentAD.psm1: -------------------------------------------------------------------------------- 1 | Import-LocalizedData -BindingVariable localizedData -filename cMMAgentAD.psd1 -BaseDirectory $PSScriptRoot -Verbose 2 | 3 | function Get-TargetResource 4 | { 5 | [OutputType([Hashtable])] 6 | param ( 7 | [Parameter(Mandatory)] 8 | [Bool] $EnableAD 9 | ) 10 | 11 | $configuration = @{ 12 | EnableAD = $EnableAD 13 | } 14 | 15 | try { 16 | Write-Verbose $localizedData.GetMMAgentConfig 17 | $mmAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 18 | $adEnabled = $mmAgentConfig.ActiveDirectoryIntegrationEnabled -eq $true 19 | 20 | if ($EnableAD -eq $adEnabled) { 21 | Write-Verbose $localizedData.FoundAD 22 | $Configuration.Add('Ensure','Present') 23 | } else { 24 | Write-Verbose $localizedData.FoundNoAD 25 | $configuration.Add('Ensure','Absent') 26 | } 27 | 28 | return $configuration 29 | } 30 | 31 | catch { 32 | $exception = $_ 33 | Write-Verbose ($localizedData.AnErrorOccurred -f $exception.message) 34 | while ($exception.InnerException -ne $null) 35 | { 36 | $exception = $exception.InnerException 37 | Write-Verbose ($localizedData.InnerException -f $exception.message) 38 | } 39 | } 40 | } 41 | 42 | function Set-TargetResource 43 | { 44 | param ( 45 | [Parameter(Mandatory)] 46 | [Bool] $EnableAD 47 | ) 48 | 49 | try { 50 | Write-Verbose $localizedData.GetMMAgentConfig 51 | $mmAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 52 | if ($EnableAD) 53 | { 54 | Write-Verbose $localizedData.EnableAD 55 | $mmAgentConfig.EnableActiveDirectoryIntegration() 56 | $mmAgentConfig.ReloadConfiguration() 57 | Write-Verbose $localizedData.EnabledAD 58 | } else { 59 | Write-Verbose $localizedData.DisableAD 60 | $mmAgentConfig.DisableActiveDirectoryIntegration() 61 | $mmAgentConfig.ReloadConfiguration() 62 | Write-Verbose $localizedData.DisabledAD 63 | } 64 | } 65 | 66 | catch { 67 | $exception = $_ 68 | Write-Verbose ($localizedData.AnErrorOccurred -f $exception.message) 69 | while ($exception.InnerException -ne $null) 70 | { 71 | $exception = $exception.InnerException 72 | Write-Verbose ($localizedData.InnerException -f $exception.message) 73 | } 74 | } 75 | 76 | } 77 | 78 | function Test-TargetResource 79 | { 80 | [OutputType([boolean])] 81 | param ( 82 | [Parameter(Mandatory)] 83 | [Bool] $EnableAD 84 | ) 85 | 86 | try { 87 | Write-Verbose $localizedData.GetMMAgentConfig 88 | $mmAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 89 | $adEnabled = $mmAgentConfig.ActiveDirectoryIntegrationEnabled -eq $true 90 | 91 | if ($EnableAD) { 92 | if ($adEnabled) { 93 | Write-Verbose $localizedData.ADEnabledNoAction 94 | return $true 95 | } else { 96 | Write-Verbose $localizedData.ADNotEnabledShouldEnable 97 | return $false 98 | } 99 | } else { 100 | if ($adEnabled) { 101 | Write-Verbose $localizedData.ADEnabledShouldDisable 102 | return $false 103 | } else { 104 | Write-Verbose $localizedData.ADNotEnabledNoAction 105 | return $true 106 | } 107 | } 108 | } 109 | 110 | catch { 111 | $exception = $_ 112 | Write-Verbose ($localizedData.AnErrorOccurred -f $exception.message) 113 | while ($exception.InnerException -ne $null) 114 | { 115 | $exception = $exception.InnerException 116 | Write-Verbose ($localizedData.InnerException -f $exception.message) 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentAD/cMMAgentAD.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/DSCResources/cMMAgentAD/cMMAgentAD.schema.mof -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentAD/en-US/cMMAgentAD.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GetMMAgentConfig=Retrieving MMAgent Configuration object 3 | FoundAD=Found Active Directory Integration enabled. 4 | FoundNoAD=Found Active Directory integration disabled. 5 | EnableAD=Enabling Active Directory integration. 6 | EnabledAD=Enabled Active Directory integration. 7 | DisableAD=Disabling Active Directory integration. 8 | DisabledAD=Disabled Active Directory integration. 9 | ADEnabledNoAction=AD integration already enabled. No action needed. 10 | ADNotEnabledShouldEnable=AD integration not enabled. This will be enabled. 11 | ADEnabledShouldDisable=AD integration enabled. This will be disabled. 12 | ADNotEnabledNoAction=AD integration not enabled. No action needed. 13 | AnErrorOccurred=An error occurred while verifying/updating AD integration. 14 | InnerException=Nested error trying to verifying/updating AD integration. 15 | '@ 16 | -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentInstall/cMMAgentInstall.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/DSCResources/cMMAgentInstall/cMMAgentInstall.psd1 -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentInstall/cMMAgentInstall.schema.psm1: -------------------------------------------------------------------------------- 1 | Configuration cMMAgentInstall { 2 | Param ( 3 | [Parameter(Mandatory)] 4 | [String]$Path, 5 | 6 | [Parameter(Mandatory)] 7 | [String]$WorkspaceID, 8 | 9 | [Parameter(Mandatory)] 10 | [String]$WorkspaceKey, 11 | 12 | [Parameter()] 13 | [ValidateSet('Present','Absent')] 14 | [String]$Ensure = 'Present' 15 | ) 16 | 17 | if ($Ensure -eq 'Absent') { 18 | $commandLineArguments = '/Q /C:"MsiExec.exe /x{E854571C-3C01-4128-99B8-52512F44E5E9} /qn /norestart"' 19 | Package MMAgentSetup { 20 | Name = 'Microsoft Monitoring Agent' 21 | ProductId = 'EB03FA06-01A7-49F7-8BD0-0AB92D905899' 22 | Path = $Path 23 | Arguments = $commandLineArguments 24 | Ensure = 'Absent' 25 | } 26 | } else { 27 | $commandLineArguments = '/Q /C:"setup.exe /qn ADD_OPINSIGHTS_WORKSPACE=1 AcceptEndUserLicenseAgreement=1 ' 28 | $commandLineArguments += "OPINSIGHTS_WORKSPACE_ID=$WorkspaceID " 29 | $commandLineArguments += "OPINSIGHTS_WORKSPACE_KEY=$WorkspaceKey`"" 30 | 31 | Package MMAgentSetup { 32 | Name = 'Microsoft Monitoring Agent' 33 | ProductId = 'E854571C-3C01-4128-99B8-52512F44E5E9' 34 | Path = $Path 35 | Arguments = $commandLineArguments 36 | Ensure = 'Present' 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentManagementGroups/cMMAgentManagementGroups.psm1: -------------------------------------------------------------------------------- 1 | Import-LocalizedData -BindingVariable localizedData -filename cMMAgentManagementGroups.psd1 -BaseDirectory $PSScriptRoot -Verbose 2 | 3 | function Get-TargetResource 4 | { 5 | [OutputType([Hashtable])] 6 | param ( 7 | [Parameter(Mandatory)] 8 | [String] $ManagementGroupName, 9 | 10 | [Parameter(Mandatory)] 11 | [String] $ManagementServerName 12 | ) 13 | 14 | $configuration = @{ 15 | managementGroupName = $ManagementGroupName 16 | managementServerName = $ManagementServerName 17 | } 18 | 19 | try { 20 | Write-Verbose $localizedData.GetMMAgentConfig 21 | $mmAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 22 | 23 | #This try-catch is a workaround for the COM method failure when the specified group does not exist 24 | try { 25 | Write-Verbose $localizedData.GetManagementGroup 26 | $managementGroup = $mmAgentConfig.GetManagementGroup($ManagementGroupName) 27 | } 28 | catch { 29 | Write-Verbose $localizedData.ManagementGroupNotFound 30 | $configuration.Add('Ensure','Absent') 31 | } 32 | 33 | if ($managementGroup) { 34 | Write-Verbose $localizedData.ManagementGroupFound 35 | $configuration.Add('Ensure','Present') 36 | } 37 | return $configuration 38 | } 39 | 40 | catch { 41 | $exception = $_ 42 | Write-Verbose ($localizedData.AnErrorOccurred -f $exception.message) 43 | while ($exception.InnerException -ne $null) 44 | { 45 | $exception = $exception.InnerException 46 | Write-Verbose ($localizedData.InnerException -f $exception.message) 47 | } 48 | } 49 | } 50 | 51 | function Set-TargetResource 52 | { 53 | param ( 54 | [Parameter(Mandatory)] 55 | [String] $managementGroupName, 56 | 57 | [Parameter(Mandatory)] 58 | [String] $managementServerName, 59 | 60 | [Parameter()] 61 | [UInt32] $managementServerPort = 5723, 62 | 63 | [Parameter()] 64 | [PSCredential] $actionAccountCredential, 65 | 66 | [Parameter()] 67 | [Bool] $Force, 68 | 69 | [Parameter()] 70 | [ValidateSet('Present','Absent')] 71 | [String] $Ensure = 'Present' 72 | ) 73 | 74 | try { 75 | Write-Verbose $LocalizedData.GetMMAgentConfig 76 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 77 | 78 | if ($Force) { 79 | if ($actionAccountCredential) { 80 | if (-not ($actionAccountCredential.GetNetworkCredential().Domain)) { 81 | $ActionDomain = $null 82 | } else { 83 | $ActionDomain = $actionAccountCredential.GetNetworkCredential().Domain 84 | } 85 | Write-Verbose $LocalizedData.UpdateActionAccount 86 | $MMAgentConfig.UpdateActionAccount($managementGroupName, $ActionDomain, $actionAccountCredential.GetNetworkCredential().UserName, $actionAccountCredential.GetNetworkCredential().Password) 87 | $MMAgentConfig.ReloadConfiguration() 88 | Write-Verbose $LocalizedData.UpdateActionAccountComplete 89 | } else { 90 | throw $LocalizedData.ActionAccountNotSpecified 91 | } 92 | } elseif ($Ensure -eq 'Present') { 93 | Write-Verbose $LocalizedData.AddingManagementGroup 94 | if ($actionAccountCredential) { 95 | if (-not ($actionAccountCredential.GetNetworkCredential().Domain)) { 96 | $ActionDomain = $null 97 | } else { 98 | $ActionDomain = $actionAccountCredential.GetNetworkCredential().Domain 99 | } 100 | $MMAgentConfig.AddManagementGroup($managementGroupName,$managementServerName,$managementServerPort, $ActionDomain, $actionAccountCredential.GetNetworkCredential().UserName, $actionAccountCredential.GetNetworkCredential().Password) 101 | } else { 102 | $MMAgentConfig.AddManagementGroup($managementGroupName,$managementServerName,$managementServerPort) 103 | } 104 | $MMAgentConfig.ReloadConfiguration() 105 | Write-Verbose $LocalizedData.AddedManagementGroup 106 | } elseif ($Ensure -eq 'Absent') { 107 | Write-Verbose $LocalizedData.RemovingManagementGroup 108 | $MMAgentConfig.RemoveManagementGroup($managementGroupName) 109 | $MMAgentConfig.ReloadConfiguration() 110 | Write-Verbose $LocalizedData.RemovedManagementGroup 111 | } 112 | } 113 | 114 | catch { 115 | $exception = $_ 116 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 117 | while ($exception.InnerException -ne $null) 118 | { 119 | $exception = $exception.InnerException 120 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 121 | } 122 | } 123 | 124 | } 125 | 126 | function Test-TargetResource 127 | { 128 | [OutputType([boolean])] 129 | param ( 130 | [Parameter(Mandatory)] 131 | [String] $managementGroupName, 132 | 133 | [Parameter(Mandatory)] 134 | [String] $managementServerName, 135 | 136 | [Parameter()] 137 | [UInt32] $managementServerPort = 5723, 138 | 139 | [Parameter()] 140 | [PSCredential] $actionAccountCredential, 141 | 142 | [Parameter()] 143 | [Bool] $Force, 144 | 145 | [Parameter()] 146 | [ValidateSet('Present','Absent')] 147 | [String] $Ensure = 'Present' 148 | ) 149 | 150 | try { 151 | Write-Verbose $localizedData.GetMMAgentConfig 152 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 153 | 154 | try { 155 | $ManagementGroup = $MMAgentConfig.GetManagementGroup($managementGroupName) 156 | } 157 | catch { 158 | Write-Verbose $localizedData.ManagementGroupNotFound 159 | } 160 | 161 | if ($Force) { 162 | Write-Verbose $localizedData.ShouldUpdateManagementGroup 163 | return $false 164 | } elseif ($Ensure -eq 'Present') { 165 | if ($ManagementGroup) { 166 | Write-Verbose $localizedData.ManagementGroupFoundNoActionNeeded 167 | return $true 168 | } else { 169 | Write-Verbose $localizedData.ManagementGroupDoesnotExistMustCreate 170 | return $false 171 | } 172 | } else { 173 | if ($ManagementGroup) { 174 | Write-Verbose $localizedData.ManagementGroupFoundMustDelete 175 | return $false 176 | } else { 177 | Write-Verbose $localizedData.ManagementGroupNotFoundNoActionNeeded 178 | return $true 179 | } 180 | } 181 | } 182 | 183 | catch { 184 | $exception = $_ 185 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 186 | while ($exception.InnerException -ne $null) 187 | { 188 | $exception = $exception.InnerException 189 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 190 | } 191 | } 192 | } -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentManagementGroups/cMMAgentManagementGroups.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/DSCResources/cMMAgentManagementGroups/cMMAgentManagementGroups.schema.mof -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentManagementGroups/en-US/cMMAgentManagementGroups.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GetMMAgentConfig=Retrieving MMAgent Configuration object. 3 | GetManagementGroup=Getting Management Group. 4 | ManagementGroupNotFound=Management Group not found. 5 | ManagementGroupFound=Management group found. 6 | ShouldUpdateManagementGroup=Management group configurtion will be updated. 7 | ManagementGroupFoundNoActionNeeded=Management group found. No action needed. 8 | ManagementGroupDoesnotExistMustCreate=Management group does not exist. It will be configured. 9 | ManagementGroupFoundMustDelete=Management group found. It will be removed. 10 | ManagementGroupNotFoundNoActionNeeded=Management group not found. No action needed. 11 | UpdateActionAccount=Action account Credentials will be updated. 12 | UpdateActionAccountComplete=Action Account Credentials updated. 13 | ActionAccountNotSpecified=Action Account credentials must be specified when setting Force property to True. 14 | AnErrorOccurred=An error occurred while working with management group. 15 | InnerException=Nested error during management group configuration. 16 | AddingManagementGroup=Adding Management Group configuration. 17 | AddedManagementGroup=Added Management Group configuration. 18 | RemovingManagementGroup=Removing Management Group Configuration. 19 | RemovedManagementGroup=Removed Management Group Configuration. 20 | '@ 21 | -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentOpInsights/cMMAgentOpInsights.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GetMMAgentConfig=Retrieving MMAgent Configuration object 7 | WorkSpaceIDExists=Azure Operational Insights with workspace ID {0} exists. 8 | WorkspaceIDDifferent=Azure Operational Insights with workspace ID {0} does not exist. 9 | AzureOpInsightNotEnabled=Azure Operational Insights is not enabled. 10 | EnableAzureOpInsights=Enabling Azure Operational Insights with Workspace ID {0}. 11 | EnabledAzureOpInsights=Enabled Azure Operational Insights with Workspace ID {0}. 12 | DisableAzureOpInsights=Disabling Azure Operational Insights with Workspace ID {0}. 13 | DisabledAzureOpInsights=Disabled Azure Operational Insights with Workspace ID {0}. 14 | ForceFound=Force property is set to True. 15 | AzureOpInsightsEnabledNoAction=Azure Operational Insights is enabled with Workspace ID {0}. No action Needed. 16 | AzureOpInsightsNotEnabledShouldEnable=Azure Operational Insights is not enabled with Workspace ID {0}. It will be enabled. 17 | AzureOpInsightsEnabledShouldRemoved=Azure Operational Insights is enabled with Workspace ID {0}. It will be disabled. 18 | AzureOpInsightsNotEnabledNoAction=Azure Operational Insights is not enabled with Workspace ID {0}. No action needed. 19 | ErrorDisablingOpInsights=There was an error disabling Azure Operational Insights. 20 | AnErrorOccurred=An error occurred while verifying/updating Azure OpInsights configuration: {0}. 21 | InnerException=Nested error trying to verifying/updating Azure OpInsights configuration: {0}. 22 | '@ 23 | } 24 | 25 | if (Test-Path $PSScriptRoot\en-us) 26 | { 27 | Import-LocalizedData LocalizedData -filename cMMAgentOpInsights.psd1 28 | } 29 | 30 | function Get-TargetResource 31 | { 32 | [OutputType([Hashtable])] 33 | param ( 34 | [Parameter(Mandatory)] 35 | [String] $WorkspaceID, 36 | 37 | [Parameter(Mandatory)] 38 | [String] $WorkspaceKey 39 | ) 40 | 41 | $Configuration = @{ 42 | WorkspaceID = $WorkspaceID 43 | WorkspaceKey = $WorkspaceKey 44 | } 45 | 46 | try { 47 | Write-Verbose $localizedData.GetMMAgentConfig 48 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 49 | if ($MMAgentConfig.AzureOperationalInsightsEnabled -eq $true) { 50 | if ($MMAgentConfig.AzureOperationalInsightsWorkspaceId -eq $WorkspaceID) { 51 | Write-Verbose ($localizedData.WorkSpaceIDExists -f $WorkspaceID) 52 | $Configuration.Add('Ensure','Present') 53 | } else { 54 | Write-Verbose ($localizedData.WorkspaceIDDifferent -f $WorkspaceID) 55 | $Configuration.Add('Ensure','Absent') 56 | } 57 | } else { 58 | Write-Verbose ($localizedData.AzureOpInsightNotEnabled) 59 | $Configuration.Add('Ensure','Absent') 60 | } 61 | 62 | return $Configuration 63 | } 64 | 65 | catch { 66 | $exception = $_ 67 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 68 | while ($exception.InnerException -ne $null) 69 | { 70 | $exception = $exception.InnerException 71 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 72 | } 73 | } 74 | } 75 | 76 | function Set-TargetResource 77 | { 78 | param ( 79 | [Parameter(Mandatory)] 80 | [String] $WorkspaceID, 81 | 82 | [Parameter(Mandatory)] 83 | [String] $WorkspaceKey, 84 | 85 | [Parameter()] 86 | [Bool] $Force, 87 | 88 | [Parameter()] 89 | [ValidateSet('Present','Absent')] 90 | [String]$Ensure='Present' 91 | ) 92 | 93 | try { 94 | Write-Verbose $LocalizedData.GetMMAgentConfig 95 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 96 | 97 | if ($Ensure -eq 'Present' -or ($Force)) 98 | { 99 | Write-Verbose ($LocalizedData.EnableAzureOpInsights -f $WorkspaceID) 100 | $MMAgentConfig.EnableAzureOperationalInsights($WorkspaceID, $WorkspaceKey) 101 | } else { 102 | Write-Verbose ($LocalizedData.DisableAzureOpInsights -f $WorkspaceID) 103 | #TODO: This results in an error for some reason but disables Azure OpInsights. 104 | #Workaround: Wrap it another try catch and don't send the error. 105 | try { 106 | $MMAgentConfig.DisableAzureOperationalInsights() 107 | } 108 | catch { 109 | if ($MMAgentConfig.AzureOperationalInsightsEnabled) { 110 | $MMAgentConfig.ReloadConfiguration() 111 | Write-Verbose ($LocalizedData.EnabledAzureOpInsights -f $WorkspaceID) 112 | } else { 113 | throw $LocalizedData.ErrorDisablingOpInsights 114 | } 115 | } 116 | } 117 | } 118 | catch { 119 | $exception = $_ 120 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 121 | while ($exception.InnerException -ne $null) 122 | { 123 | $exception = $exception.InnerException 124 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 125 | } 126 | } 127 | 128 | } 129 | 130 | function Test-TargetResource 131 | { 132 | [OutputType([boolean])] 133 | param ( 134 | [Parameter(Mandatory)] 135 | [String] $WorkspaceID, 136 | 137 | [Parameter(Mandatory)] 138 | [String] $WorkspaceKey, 139 | 140 | [Parameter()] 141 | [Bool] $Force, 142 | 143 | [Parameter()] 144 | [ValidateSet('Present','Absent')] 145 | [String]$Ensure='Present' 146 | ) 147 | 148 | try { 149 | Write-Verbose $localizedData.GetMMAgentConfig 150 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 151 | 152 | if ($MMAgentConfig.AzureOperationalInsightsEnabled -eq $true) { 153 | if ($MMAgentConfig.AzureOperationalInsightsWorkspaceId -eq $WorkspaceID) { 154 | $AzureOpInsightsEnabled = $true 155 | } else { 156 | $AzureOpInsightsEnabled = $false 157 | } 158 | } else { 159 | $AzureOpInsightsEnabled = $false 160 | } 161 | 162 | if ($Force) { 163 | Write-Verbose $localizedData.ForceFound 164 | return $false 165 | } elseif ($Ensure -eq 'Present') { 166 | if ($AzureOpInsightsEnabled) { 167 | Write-Verbose ($localizedData.AzureOpInsightsEnabledNoAction -f $WorkspaceID) 168 | return $true 169 | } else { 170 | Write-Verbose ($localizedData.AzureOpInsightsNotEnabledShouldEnable -f $WorkspaceID) 171 | return $false 172 | } 173 | } else { 174 | if ($AzureOpInsightsEnabled) { 175 | Write-Verbose ($localizedData.AzureOpInsightsEnabledShouldRemoved -f $WorkspaceID) 176 | return $false 177 | } else { 178 | Write-Verbose ($localizedData.AzureOpInsightsNotEnabledNoAction -f $WorkspaceID) 179 | return $true 180 | } 181 | } 182 | } 183 | 184 | catch { 185 | $exception = $_ 186 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 187 | while ($exception.InnerException -ne $null) 188 | { 189 | $exception = $exception.InnerException 190 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 191 | } 192 | } 193 | } -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentOpInsights/cMMAgentOpInsights.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/DSCResources/cMMAgentOpInsights/cMMAgentOpInsights.schema.mof -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentOpInsights/en-US/cMMAgentOpInsights.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GetMMAgentConfig=Retrieving MMAgent Configuration object 3 | WorkSpaceIDExists=Azure Operational Insights with workspace ID {0} exists. 4 | WorkspaceIDDifferent=Azure Operational Insights with workspace ID {0} does not exist. 5 | AzureOpInsightNotEnabled=Azure Operational Insights is not enabled. 6 | EnableAzureOpInsights=Enabling Azure Operational Insights with Workspace ID {0}. 7 | EnabledAzureOpInsights=Enabled Azure Operational Insights with Workspace ID {0}. 8 | DisableAzureOpInsights=Disabling Azure Operational Insights with Workspace ID {0}. 9 | DisabledAzureOpInsights=Disabled Azure Operational Insights with Workspace ID {0}. 10 | ForceFound=Force property is set to True. 11 | AzureOpInsightsEnabledNoAction=Azure Operational Insights is enabled with Workspace ID {0}. No action Needed. 12 | AzureOpInsightsNotEnabledShouldEnable=Azure Operational Insights is not enabled with Workspace ID {0}. It will be enabled. 13 | AzureOpInsightsEnabledShouldRemoved=Azure Operational Insights is enabled with Workspace ID {0}. It will be disabled. 14 | AzureOpInsightsNotEnabledNoAction=Azure Operational Insights is not enabled with Workspace ID {0}. No action needed. 15 | ErrorDisablingOpInsights=There was an error disabling Azure Operational Insights. 16 | AnErrorOccurred=An error occurred while verifying/updating Azure OpInsights configuration: {0}. 17 | InnerException=Nested error trying to verifying/updating Azure OpInsights configuration: {0}. 18 | '@ 19 | -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentProxyCredential/cMMAgentProxyCredential.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GetMMAgentConfig=Retrieving MMAgent Configuration object. 7 | FoundProxyUser=Found proxyusername as supplied {0}. 8 | FoundNoProxyUser=Found no proxyusername as supplied {0}. 9 | SetProxyName=Setting proxy configuration to supplied URL {0}. 10 | UpdateProxyCredential=Updating proxy credential configuration to supplied username {0} and password. 11 | UpdatedProxyCredential=Updated/configured proxy credential to supplied username {0} and password. 12 | SetProxyCredential=Setting proxy credential to supplied username {0} and password. 13 | RemoveProxyCredential=Removing proxy credential for username {0}. 14 | RemovedProxyCredential=Removed proxy credential for username {0}. 15 | ForceFound=Force property is set to True. 16 | ProxyUserExistsNoAction=Proxy credential configuration exists with username {0}. No action needed. 17 | ProxyUserDoesNotExistShouldAdd=Proxy credential configuration does not exist for username {0}. It will be configured. 18 | ProxyUserExistsShouldRemove=Proxy credential configuration exists for username {0}. It will be removed. 19 | ProxyUserDoesnotExistNoAction=Proxy credential configuration does not exist for username {0}. No action needed. 20 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 21 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 22 | '@ 23 | } 24 | 25 | if (Test-Path $PSScriptRoot\en-us) 26 | { 27 | Import-LocalizedData LocalizedData -filename cMMAgentProxyCredential.psd1 28 | } 29 | 30 | function Get-TargetResource 31 | { 32 | [OutputType([Hashtable])] 33 | param ( 34 | [Parameter(Mandatory)] 35 | [String] $ProxyUserName, 36 | 37 | [Parameter(Mandatory)] 38 | [PSCredential] $ProxyUserPassword 39 | ) 40 | 41 | $Configuration = @{ 42 | ProxyUserName = $ProxyUserName 43 | ProxyUserPassword = $ProxyUserPassword 44 | } 45 | 46 | try { 47 | Write-Verbose $localizedData.GetMMAgentConfig 48 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 49 | if ($MMAgentConfig.proxyUsername -eq $ProxyUserName) { 50 | Write-Verbose ($localizedData.FoundProxyUser -f $ProxyUserName) 51 | $Configuration.Add('Ensure','Present') 52 | } else { 53 | Write-Verbose ($localizedData.FoundNoProxyUser -f $ProxyUserName) 54 | $Configuration.Add('Ensure','Absent') 55 | } 56 | 57 | return $Configuration 58 | } 59 | 60 | catch { 61 | $exception = $_ 62 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 63 | while ($exception.InnerException -ne $null) 64 | { 65 | $exception = $exception.InnerException 66 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 67 | } 68 | } 69 | } 70 | 71 | function Set-TargetResource 72 | { 73 | param ( 74 | [Parameter(Mandatory)] 75 | [String] $ProxyUserName, 76 | 77 | [Parameter(Mandatory)] 78 | [PSCredential] $ProxyUserPassword, 79 | 80 | [Parameter()] 81 | [Bool] $Force, 82 | 83 | [Parameter()] 84 | [ValidateSet('Present','Absent')] 85 | [String] $Ensure='Present' 86 | ) 87 | 88 | try { 89 | Write-Verbose $LocalizedData.GetMMAgentConfig 90 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 91 | if ($Force) { 92 | Write-Verbose $LocalizedData.UpdateProxyCredential 93 | $MMAgentConfig.SetProxyCredentials($ProxyUserName, $ProxyUserPassword.GetNetworkCredential().Password) 94 | Write-Verbose $LocalizedData.UpdatedProxyCredential 95 | } elseif ($Ensure -eq 'Present') { 96 | Write-Verbose ($LocalizedData.SetProxyCredential -f $ProxyUserName) 97 | $MMAgentConfig.SetProxyCredentials($ProxyUserName, $ProxyUserPassword.GetNetworkCredential().Password) 98 | Write-Verbose ($LocalizedData.UpdatedProxyCredential -f $ProxyUserName) 99 | } else { 100 | Write-Verbose ($LocalizedData.RemoveProxyCredential -f $ProxyUserName) 101 | $MMAgentConfig.SetProxyCredentials($null,$null) 102 | Write-Verbose ($LocalizedData.RemovedProxyCredential -f $ProxyUserName) 103 | } 104 | } 105 | catch { 106 | $exception = $_ 107 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 108 | while ($exception.InnerException -ne $null) 109 | { 110 | $exception = $exception.InnerException 111 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 112 | } 113 | } 114 | 115 | } 116 | 117 | function Test-TargetResource 118 | { 119 | [OutputType([boolean])] 120 | param ( 121 | [Parameter(Mandatory)] 122 | [String] $ProxyUserName, 123 | 124 | [Parameter(Mandatory)] 125 | [PSCredential] $ProxyUserPassword, 126 | 127 | [Parameter()] 128 | [Bool] $Force, 129 | 130 | [Parameter()] 131 | [ValidateSet('Present','Absent')] 132 | [String] $Ensure='Present' 133 | ) 134 | 135 | try { 136 | if ($Force) { 137 | Write-Verbose $LocalizedData.ForceFound 138 | return $false 139 | } else { 140 | Write-Verbose $localizedData.GetMMAgentConfig 141 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 142 | 143 | $ProxyUserExists = $MMAgentConfig.proxyUsername -eq $ProxyUserName 144 | 145 | if ($Ensure -eq 'Present') { 146 | if ($ProxyUserExists) { 147 | Write-Verbose ($localizedData.ProxyUserExistsNoAction -f $ProxyUserName) 148 | return $true 149 | } else { 150 | Write-Verbose ($localizedData.ProxyUserDoesNotExistShouldAdd -f $ProxyUserName) 151 | return $false 152 | } 153 | } else { 154 | if ($ProxyUserExists) { 155 | Write-Verbose ($localizedData.ProxyUserExistsShouldRemove -f $ProxyUserName) 156 | return $false 157 | } else { 158 | Write-Verbose ($localizedData.ProxyUserDoesnotExistNoAction -f $ProxyUserName) 159 | return $true 160 | } 161 | } 162 | 163 | } 164 | } 165 | 166 | catch { 167 | $exception = $_ 168 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 169 | while ($exception.InnerException -ne $null) 170 | { 171 | $exception = $exception.InnerException 172 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 173 | } 174 | } 175 | } -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentProxyCredential/cMMAgentProxyCredential.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/DSCResources/cMMAgentProxyCredential/cMMAgentProxyCredential.schema.mof -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentProxyCredential/en-US/cMMAgentProxyCredential.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GetMMAgentConfig=Retrieving MMAgent Configuration object. 3 | FoundProxyUser=Found proxyusername as supplied {0}. 4 | FoundNoProxyUser=Found no proxyusername as supplied {0}. 5 | SetProxyName=Setting proxy configuration to supplied URL {0}. 6 | UpdateProxyCredential=Updating proxy credential configuration to supplied username {0} and password. 7 | UpdatedProxyCredential=Updated/configured proxy credential to supplied username {0} and password. 8 | SetProxyCredential=Setting proxy credential to supplied username {0} and password. 9 | RemoveProxyCredential=Removing proxy credential for username {0}. 10 | RemovedProxyCredential=Removed proxy credential for username {0}. 11 | ForceFound=Force property is set to True. 12 | ProxyUserExistsNoAction=Proxy credential configuration exists with username {0}. No action needed. 13 | ProxyUserDoesNotExistShouldAdd=Proxy credential configuration does not exist for username {0}. It will be configured. 14 | ProxyUserExistsShouldRemove=Proxy credential configuration exists for username {0}. It will be removed. 15 | ProxyUserDoesnotExistNoAction=Proxy credential configuration does not exist for username {0}. No action needed. 16 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 17 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 18 | '@ 19 | -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentProxyName/cMMAgentProxyName.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GetMMAgentConfig=Retrieving MMAgent Configuration object 7 | FoundProxy=Found proxy with URL {0} 8 | FoundNoProxy=Found no proxy configuration with URL {0} 9 | SetProxyName=Setting proxy configuration to supplied URL {0} 10 | UpdatedProxyName=Updated proxy configuration to supplied URL {0} 11 | RemoveProxyName=Removing proxy configuration for URL {0} 12 | RemovedProxyName=Removed proxy configuration for URL {0} 13 | ProxyExistsNoAction=Proxy configuration exists with URL {0}. No action needed. 14 | ProxyDoesNotExistShouldAdd=Proxy configuration does not exist for URL {0}. It will be configured. 15 | ProxyExistsShouldRemove=Proxy configuration exists with URL {0}. It will be removed. 16 | ProxyDoesnotExistNoAction=Proxy configuration does not exist for URL {0}. No action needed. 17 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 18 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 19 | '@ 20 | } 21 | 22 | if (Test-Path $PSScriptRoot\en-us) 23 | { 24 | Import-LocalizedData LocalizedData -filename cMMAgentProxyName.psd1 25 | } 26 | 27 | function Get-TargetResource 28 | { 29 | [OutputType([Hashtable])] 30 | param ( 31 | [Parameter(Mandatory)] 32 | [ValidateScript({$_.Startswith('http') -or $_.Startswith('https')})] 33 | [String] $ProxyName 34 | ) 35 | 36 | $Configuration = @{ 37 | ProxyName = $ProxyName 38 | } 39 | 40 | try { 41 | Write-Verbose $localizedData.GetMMAgentConfig 42 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 43 | if ($MMAgentConfig.proxyUrl -eq $ProxyName) { 44 | $Configuration.Add('Ensure','Present') 45 | } else { 46 | Write-Verbose ($localizedData.FoundNoProxy -f $ProxyName) 47 | $Configuration.Add('Ensure','Absent') 48 | } 49 | 50 | return $Configuration 51 | } 52 | 53 | catch { 54 | $exception = $_ 55 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 56 | while ($exception.InnerException -ne $null) 57 | { 58 | $exception = $exception.InnerException 59 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 60 | } 61 | } 62 | } 63 | 64 | function Set-TargetResource 65 | { 66 | param ( 67 | [Parameter(Mandatory)] 68 | [ValidateScript({$_.Startswith('http') -or $_.Startswith('https')})] 69 | [String] $ProxyName, 70 | 71 | [Parameter()] 72 | [ValidateSet('Present','Absent')] 73 | [String]$Ensure='Present' 74 | ) 75 | 76 | try { 77 | Write-Verbose $LocalizedData.GetMMAgentConfig 78 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 79 | if ($Ensure -eq 'Present') 80 | { 81 | Write-Verbose ($LocalizedData.SetProxyName -f $ProxyName) 82 | $MMAgentConfig.SetProxyUrl($ProxyName) 83 | $MMAgentConfig.ReloadConfiguration() 84 | Write-Verbose ($LocalizedData.UpdatedProxyName -f $ProxyName) 85 | } else { 86 | Write-Verbose ($LocalizedData.RemoveProxyName -f $ProxyName) 87 | $MMAgentConfig.SetProxyUrl($null) 88 | $MMAgentConfig.ReloadConfiguration() 89 | Write-Verbose ($LocalizedData.RemovedProxyName -f $ProxyName) 90 | } 91 | } 92 | catch { 93 | $exception = $_ 94 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 95 | while ($exception.InnerException -ne $null) 96 | { 97 | $exception = $exception.InnerException 98 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 99 | } 100 | } 101 | 102 | } 103 | 104 | function Test-TargetResource 105 | { 106 | [OutputType([boolean])] 107 | param ( 108 | [Parameter(Mandatory)] 109 | [ValidateScript({$_.Startswith('http') -or $_.Startswith('https')})] 110 | [String] $ProxyName, 111 | 112 | [Parameter()] 113 | [ValidateSet('Present','Absent')] 114 | [String]$Ensure='Present' 115 | ) 116 | 117 | try { 118 | Write-Verbose $localizedData.GetMMAgentConfig 119 | $MMAgentConfig = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' 120 | $ProxyExists = $MMAgentConfig.proxyUrl -eq $ProxyName 121 | 122 | if ($Ensure -eq 'Present') { 123 | if ($ProxyExists) { 124 | Write-Verbose ($localizedData.ProxyExistsNoAction -f $ProxyName) 125 | return $true 126 | } else { 127 | Write-Verbose ($localizedData.ProxyDoesNotExistShouldAdd -f $ProxyName) 128 | return $false 129 | } 130 | } else { 131 | if ($ProxyExists) { 132 | Write-Verbose ($localizedData.ProxyExistsShouldRemove -f $ProxyName) 133 | return $false 134 | } else { 135 | Write-Verbose ($localizedData.ProxyDoesnotExistNoAction -f $ProxyName) 136 | return $true 137 | } 138 | } 139 | } 140 | 141 | catch { 142 | $exception = $_ 143 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 144 | while ($exception.InnerException -ne $null) 145 | { 146 | $exception = $exception.InnerException 147 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 148 | } 149 | } 150 | } -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentProxyName/cMMAgentProxyName.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/DSCResources/cMMAgentProxyName/cMMAgentProxyName.schema.mof -------------------------------------------------------------------------------- /cMMAgent/DSCResources/cMMAgentProxyName/en-US/cMMAgentProxyName.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GetMMAgentConfig=Retrieving MMAgent Configuration object 3 | FoundProxy=Found proxy with URL {0} 4 | FoundNoProxy=Found no proxy configuration with URL {0} 5 | SetProxyName=Setting proxy configuration to supplied URL {0} 6 | UpdatedProxyName=Updated proxy configuration to supplied URL {0} 7 | RemoveProxyName=Removing proxy configuration for URL {0} 8 | RemovedProxyName=Removed proxy configuration for URL {0} 9 | ProxyExistsNoAction=Proxy configuration exists with URL {0}. No action needed. 10 | ProxyDoesNotExistShouldAdd=Proxy configuration does not exist for URL {0}. It will be configured. 11 | ProxyExistsShouldRemove=Proxy configuration exists with URL {0}. It will be removed. 12 | ProxyDoesnotExistNoAction=Proxy configuration does not exist for URL {0}. No action needed. 13 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 14 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 15 | '@ 16 | -------------------------------------------------------------------------------- /cMMAgent/cMMAgent.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMMAgent/cMMAgent.psd1 -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSAgentInstall/cMARSAgentInstall.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMicrosoftAzureRecoveryServices/DSCResources/cMARSAgentInstall/cMARSAgentInstall.psd1 -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSAgentInstall/cMARSAgentInstall.schema.psm1: -------------------------------------------------------------------------------- 1 | Configuration cMARSAgentInstall { 2 | Param ( 3 | [Parameter(Mandatory)] 4 | [String] $SetupPath, 5 | 6 | [Parameter()] 7 | [Bool] $EnableWindowsUpdate = $false, 8 | 9 | [Parameter()] 10 | [ValidateSet('Present','Absent')] 11 | [String] $Ensure = 'Present' 12 | ) 13 | 14 | if ($Ensure -eq 'Absent') { 15 | $CommandLineArguments = '/q /d' 16 | Package AzureBackupSetup { 17 | Name = 'Microsoft Azure Recovery Services Agent' 18 | ProductId = 'FFE6D16C-3F87-4192-AF94-DDBEFF165106' 19 | Path = $SetupPath 20 | Arguments = $CommandLineArguments 21 | Ensure = 'Absent' 22 | } 23 | } else { 24 | $CommandLineArguments = "/q " 25 | if ($EnableWindowsUpdate) { 26 | $CommandLineArguments += '/m' 27 | } else { 28 | $CommandLineArguments += '/nu' 29 | } 30 | 31 | Package AzureBackupSetup { 32 | Name = 'Microsoft Azure Recovery Services Agent' 33 | ProductId = 'FFE6D16C-3F87-4192-AF94-DDBEFF165106' 34 | Path = $SetupPath 35 | Arguments = $CommandLineArguments 36 | Ensure = 'Present' 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSEncryptionPhrase/cMARSEncryptionPhrase.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | AlreadySet=An encryption passphrase is already set. 7 | NotSet=An encryption passphrase is not set. 8 | SetPassPhrase=Setting encryption pass phrase. 9 | PassPhraseSetComplete=Setting encryption pass phrase complete. 10 | AbsentNotImplemented=Absent not implemented. Please use cMARSAgentInstall to uninstall the agent. 11 | ForceFound=Force property found. Pass phrase will be updated. 12 | PassPhraseSetNoAction=Pass phrase already set. No action needed. 13 | PassPhraseNotSetShouldAdd=Pass phrase not set. It will be added. 14 | PassPhraseSetShouldRemove=Pass phrase set. It will be removed. 15 | PassPhraseNotSetNoAction=Pass phrase not set. No action needed. 16 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 17 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 18 | '@ 19 | } 20 | 21 | if (Test-Path $PSScriptRoot\en-us) 22 | { 23 | Import-LocalizedData LocalizedData -filename cMARSEncryptionPhrase.psd1 24 | } 25 | 26 | function Get-TargetResource 27 | { 28 | [OutputType([Hashtable])] 29 | param ( 30 | [Parameter(Mandatory)] 31 | [String] $EncryptionPassPhrase 32 | ) 33 | 34 | $Configuration = @{ 35 | EncryptionPassPhrase = $EncryptionPassPhrase 36 | } 37 | 38 | try { 39 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 40 | Import-Module -Name MSOnlineBackup 41 | } 42 | 43 | catch { 44 | throw $localizedData.MSOnlineBackupNotFound 45 | } 46 | 47 | try { 48 | $KeyStatus = (Get-OBMachineSetting | Select -ExpandProperty EncryptionSetting).EncryptionKeyStatus 49 | if ($KeyStatus -eq 'Set') { 50 | Write-Verbose $localizedData.AlreadySet 51 | $Configuration.Add('Ensure','Present') 52 | } else { 53 | Write-Verbose $localizedData.NotSet 54 | $Configuration.Add('Ensure','Absent') 55 | } 56 | 57 | return $Configuration 58 | } 59 | 60 | catch { 61 | $exception = $_ 62 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 63 | while ($exception.InnerException -ne $null) 64 | { 65 | $exception = $exception.InnerException 66 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 67 | } 68 | } 69 | } 70 | 71 | function Set-TargetResource 72 | { 73 | param ( 74 | [Parameter(Mandatory)] 75 | [String] $EncryptionPassPhrase = 'Dell12345678901234', 76 | 77 | [Parameter()] 78 | [Bool] $Force, 79 | 80 | [Parameter()] 81 | [ValidateSet('Present','Absent')] 82 | [String] $Ensure = 'Present' 83 | ) 84 | 85 | try { 86 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 87 | Import-Module -Name MSOnlineBackup 88 | } 89 | 90 | catch { 91 | throw $localizedData.MSOnlineBackupNotFound 92 | } 93 | 94 | try { 95 | if (($Ensure -eq 'Present') -or $Force) { 96 | Write-Verbose $LocalizedData.SetPassPhrase 97 | $SecureString = ConvertTo-SecureString -String $EncryptionPassPhrase -AsPlainText -Force 98 | Set-OBMachineSetting -EncryptionPassphrase $SecureString 99 | Write-Verbose $LocalizedData.PassPhraseSetComplete 100 | } else { 101 | Write-Verbose $localizedData.AbsentNotImplemented 102 | } 103 | } 104 | catch { 105 | $exception = $_ 106 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 107 | while ($exception.InnerException -ne $null) 108 | { 109 | $exception = $exception.InnerException 110 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 111 | } 112 | } 113 | } 114 | 115 | function Test-TargetResource 116 | { 117 | [OutputType([boolean])] 118 | param ( 119 | [Parameter(Mandatory)] 120 | [String] $EncryptionPassPhrase, 121 | 122 | [Parameter()] 123 | [Bool] $Force, 124 | 125 | [Parameter()] 126 | [ValidateSet('Present','Absent')] 127 | [String] $Ensure = 'Present' 128 | ) 129 | 130 | try { 131 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 132 | Import-Module -Name MSOnlineBackup 133 | } 134 | 135 | catch { 136 | throw $localizedData.MSOnlineBackupNotFound 137 | } 138 | 139 | try { 140 | $KeyStatus = (Get-OBMachineSetting | Select -ExpandProperty EncryptionSetting).EncryptionKeyStatus 141 | if ($Force) { 142 | Write-Verbose $localizedData.ForceFound 143 | return $false 144 | } elseif ($Ensure -eq 'Present') { 145 | if ($KeyStatus -eq 'Set') { 146 | Write-Verbose ($localizedData.PassPhraseSetNoAction) 147 | return $true 148 | } else { 149 | Write-Verbose ($localizedData.PassPhraseNotSetShouldAdd) 150 | return $false 151 | } 152 | } else { 153 | if ($KeyStatus -eq 'Set') { 154 | Write-Verbose ($localizedData.PassPhraseSetShouldRemove) 155 | return $false 156 | } else { 157 | Write-Verbose ($localizedData.PassPhraseNotSetNoAction) 158 | return $true 159 | } 160 | } 161 | } 162 | 163 | catch { 164 | $exception = $_ 165 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 166 | while ($exception.InnerException -ne $null) 167 | { 168 | $exception = $exception.InnerException 169 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 170 | } 171 | } 172 | } -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSEncryptionPhrase/cMARSEncryptionPhrase.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMicrosoftAzureRecoveryServices/DSCResources/cMARSEncryptionPhrase/cMARSEncryptionPhrase.schema.mof -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSEncryptionPhrase/en-US/cMARSEncryptionPhrase.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | AlreadySet=An encryption passphrase is already set. 3 | NotSet=An encryption passphrase is not set. 4 | SetPassPhrase=Setting encryption pass phrase. 5 | PassPhraseSetComplete=Setting encryption pass phrase complete. 6 | AbsentNotImplemented=Absent not implemented. Please use cMARSAgentInstall to uninstall the agent. 7 | ForceFound=Force property found. Pass phrase will be updated. 8 | PassPhraseSetNoAction=Pass phrase already set. No action needed. 9 | PassPhraseNotSetShouldAdd=Pass phrase not set. It will be added. 10 | PassPhraseSetShouldRemove=Pass phrase set. It will be removed. 11 | PassPhraseNotSetNoAction=Pass phrase not set. No action needed. 12 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 13 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 14 | '@ 15 | -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSProxy/cMARSProxy.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | MSOnlineBackupNotFound=MSOnlineBackup module was not found. This is required for the DSC resource. 7 | ProxySettingFound=ProxySetting configuration found. 8 | ProxySettingNotFound=Found no ProxySetting configuration. 9 | ForceFound=Force property found. Proxy configuration will be updated. 10 | ProxySettingExistsNoAction=ProxySetting Configuration {0} as proxy server Exists. No Action needed. 11 | ProxySettingDoesNotExistShouldAdd=ProxySetting Configuration {0} as proxy server does not exist. It will be added. 12 | ProxySettingExistsShouldRemove=ProxySetting Configuration {0} as proxy server Exists. It will be removed. 13 | ProxySettingDoesNotExistNoAction=ProxySetting Configuration {0} as proxy server does not exist. No action needed. 14 | UpdateProxySetting=Updating proxy setting configuration for {0}. 15 | UpdatedProxySetting=Updated proxy setting configuration for {0}. 16 | RemoveProxySetting=Removing proxy setting configuration for {0}. 17 | RemovedProxySetting=Removed proxy setting configuration for {0}. 18 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 19 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 20 | '@ 21 | } 22 | 23 | if (Test-Path $PSScriptRoot\en-us) 24 | { 25 | Import-LocalizedData LocalizedData -filename cMARSProxy.psd1 26 | } 27 | 28 | function Get-TargetResource 29 | { 30 | [OutputType([Hashtable])] 31 | param ( 32 | [Parameter(Mandatory)] 33 | [String] $ProxyServer 34 | ) 35 | 36 | $Configuration = @{ 37 | ProxyServer = $ProxyServer 38 | } 39 | 40 | try { 41 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 42 | Import-Module -Name MSOnlineBackup 43 | } 44 | 45 | catch { 46 | throw $localizedData.MSOnlineBackupNotFound 47 | } 48 | 49 | try { 50 | $MachineSetting = Get-OBMachineSetting 51 | if ($MachineSetting.ProxySetting.Enabled) { 52 | if ($MachineSetting.ProxySetting.ProxyServer -eq $ProxyServer) { 53 | Write-Verbose $localizedData.ProxySettingFound 54 | $Configuration.Add('ProxyPort',$MachineSetting.ProxySetting.ProxyPort) 55 | $Configuration.Add('Ensure','Present') 56 | } else { 57 | Write-Verbose $localizedData.ProxySettingNotFound 58 | $Configuration.Add('Ensure','Absent') 59 | } 60 | } else { 61 | Write-Verbose $localizedData.ProxySettingNotFound 62 | $Configuration.Add('Ensure','Absent') 63 | } 64 | 65 | return $Configuration 66 | } 67 | 68 | catch { 69 | $exception = $_ 70 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 71 | while ($exception.InnerException -ne $null) 72 | { 73 | $exception = $exception.InnerException 74 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 75 | } 76 | } 77 | } 78 | 79 | function Set-TargetResource 80 | { 81 | param ( 82 | [Parameter(Mandatory)] 83 | [String] $ProxyServer, 84 | 85 | [Parameter()] 86 | [Uint32] $ProxyPort = 80, 87 | 88 | [Parameter()] 89 | [PSCredential] $ProxyCredential, 90 | 91 | [Parameter()] 92 | [Bool] $Force, 93 | 94 | [Parameter()] 95 | [ValidateSet('Present','Absent')] 96 | [String] $Ensure = 'Present' 97 | ) 98 | 99 | try { 100 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 101 | Import-Module -Name MSOnlineBackup 102 | } 103 | 104 | catch { 105 | throw $localizedData.MSOnlineBackupNotFound 106 | } 107 | 108 | try { 109 | if ($Force -or $Ensure -eq 'Present') { 110 | Write-Verbose $LocalizedData.UpdateProxySetting 111 | if ($ProxyCredential) { 112 | Set-OBMachineSetting -ProxyServer $ProxyServer -ProxyPort $ProxyPort -ProxyUsername $ProxyCredential.UserName -ProxyPassword $ProxyCredential.Password 113 | } else { 114 | Set-OBMachineSetting -ProxyServer $ProxyServer -ProxyPort $ProxyPort 115 | } 116 | Write-Verbose $LocalizedData.UpdatedProxySetting 117 | } else { 118 | Write-Verbose ($LocalizedData.RemoveProxySetting -f $ProxyUserName) 119 | Set-OBMachineSetting -NoProxy 120 | Write-Verbose ($LocalizedData.RemovedProxySetting -f $ProxyUserName) 121 | } 122 | } 123 | catch { 124 | $exception = $_ 125 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 126 | while ($exception.InnerException -ne $null) 127 | { 128 | $exception = $exception.InnerException 129 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 130 | } 131 | } 132 | } 133 | 134 | function Test-TargetResource 135 | { 136 | [OutputType([boolean])] 137 | param ( 138 | [Parameter(Mandatory)] 139 | [String] $ProxyServer, 140 | 141 | [Parameter()] 142 | [Uint32] $ProxyPort = 80, 143 | 144 | [Parameter()] 145 | [PSCredential] $ProxyCredential, 146 | 147 | [Parameter()] 148 | [Bool] $Force, 149 | 150 | [Parameter()] 151 | [ValidateSet('Present','Absent')] 152 | [String] $Ensure = 'Present' 153 | ) 154 | 155 | try { 156 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 157 | Import-Module -Name MSOnlineBackup 158 | } 159 | 160 | catch { 161 | throw $localizedData.MSOnlineBackupNotFound 162 | } 163 | 164 | try { 165 | if ($Force) { 166 | Write-Verbose $LocalizedData.ForceFound 167 | return $false 168 | } else { 169 | $MachineSetting = Get-OBMachineSetting 170 | $ProxySettingExists = (($MachineSetting.ProxySetting.ProxyPort -eq $ProxyPort) -and ($MachineSetting.ProxySetting.ProxyServer -eq $ProxyServer)) 171 | 172 | if ($Ensure -eq 'Present') { 173 | if ($ProxySettingExists) { 174 | Write-Verbose ($localizedData.ProxySettingExistsNoAction -f $ProxyServer) 175 | return $true 176 | } else { 177 | Write-Verbose ($localizedData.ProxySettingDoesNotExistShouldAdd -f $ProxyServer) 178 | return $false 179 | } 180 | } else { 181 | if ($ProxySettingExists) { 182 | Write-Verbose ($localizedData.ProxySettingExistsShouldRemove -f $ProxyUserName) 183 | return $false 184 | } else { 185 | Write-Verbose ($localizedData.ProxySettingDoesNotExistNoAction -f $ProxyUserName) 186 | return $true 187 | } 188 | } 189 | 190 | } 191 | } 192 | 193 | catch { 194 | $exception = $_ 195 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 196 | while ($exception.InnerException -ne $null) 197 | { 198 | $exception = $exception.InnerException 199 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 200 | } 201 | } 202 | } -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSProxy/cMARSProxy.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cMARSProxy")] 2 | class cMARSProxy: OMI_BaseResource 3 | { 4 | [Key] string ProxyServer; 5 | [Write] Uint32 ProxyPort; 6 | [Write,EmbeddedInstance("MSFT_Credential")] string ProxyCredential; 7 | [write] boolean Force; 8 | [Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 9 | }; -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSProxy/en-US/cMARSProxy.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | MSOnlineBackupNotFound=MSOnlineBackup module was not found. This is required for the DSC resource. 3 | ProxySettingFound=ProxySetting configuration found. 4 | ProxySettingNotFound=Found no ProxySetting configuration. 5 | ForceFound=Force property found. Proxy configuration will be updated. 6 | ProxySettingExistsNoAction=ProxySetting Configuration {0} as proxy server Exists. No Action needed. 7 | ProxySettingDoesNotExistShouldAdd=ProxySetting Configuration {0} as proxy server does not exist. It will be added. 8 | ProxySettingExistsShouldRemove=ProxySetting Configuration {0} as proxy server Exists. It will be removed. 9 | ProxySettingDoesNotExistNoAction=ProxySetting Configuration {0} as proxy server does not exist. No action needed. 10 | UpdateProxySetting=Updating proxy setting configuration for {0}. 11 | UpdatedProxySetting=Updated proxy setting configuration for {0}. 12 | RemoveProxySetting=Removing proxy setting configuration for {0}. 13 | RemovedProxySetting=Removed proxy setting configuration for {0}. 14 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 15 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 16 | '@ 17 | -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSRegistration/cMARSRegistration.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | AlreadyRegistered=Already Registered with an Azure Backup Vault. 7 | NotRegistered=Not registered with an Azure Backup Vault 8 | ProxySettingNotFound=Found no ProxySetting configuration. 9 | MSOnlineBackupNotFound=MSonlineBackup module not found. 10 | RegisterServer=Server will be registered with Azure Backup Vault. 11 | RegisteredServer=Server registration complete. 12 | AbsentNotImplemented=Absent not implemented. Please use cMARSAgentInstall to uninstall the agent. 13 | RegistrationExistsNoAction=Registration Already exists. No Action needed. 14 | RegistrationNotFoundShouldAdd=Registration does not exist. Server will be registered. 15 | RegistartionExistsShouldDelete=Registration already exists. It should be removed. 16 | RegistrationNotFoundNoAction=Registration does not exist. No action needed. 17 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 18 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 19 | '@ 20 | } 21 | 22 | if (Test-Path $PSScriptRoot\en-us) 23 | { 24 | Import-LocalizedData LocalizedData -filename cMARSRegistration.psd1 25 | } 26 | 27 | function Get-TargetResource 28 | { 29 | [OutputType([Hashtable])] 30 | param ( 31 | [Parameter(Mandatory)] 32 | [String] $VaultCredential 33 | ) 34 | 35 | $Configuration = @{ 36 | VaultCredential = $VaultCredential 37 | } 38 | 39 | try { 40 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 41 | Import-Module -Name MSOnlineBackup 42 | } 43 | 44 | catch { 45 | throw $localizedData.MSOnlineBackupNotFound 46 | } 47 | 48 | try { 49 | $RegistrationStatus = [Microsoft.Internal.CloudBackup.Client.Common.CBClientCommon]::GetMachineRegistrationStatus($true) 50 | if ($RegistrationStatus) { 51 | Write-Verbose $localizedData.AlreadyRegistered 52 | $Configuration.Add('Ensure','Present') 53 | } else { 54 | Write-Verbose $localizedData.NotRegistered 55 | $Configuration.Add('Ensure','Absent') 56 | } 57 | 58 | return $Configuration 59 | } 60 | 61 | catch { 62 | $exception = $_ 63 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 64 | while ($exception.InnerException -ne $null) 65 | { 66 | $exception = $exception.InnerException 67 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 68 | } 69 | } 70 | } 71 | 72 | function Set-TargetResource 73 | { 74 | param ( 75 | [Parameter(Mandatory)] 76 | [String] $VaultCredential, 77 | 78 | [Parameter()] 79 | [ValidateSet('Present','Absent')] 80 | [String] $Ensure = 'Present' 81 | ) 82 | 83 | try { 84 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 85 | Import-Module -Name MSOnlineBackup 86 | } 87 | 88 | catch { 89 | throw $localizedData.MSOnlineBackupNotFound 90 | } 91 | 92 | try { 93 | if ($Ensure -eq 'Present') { 94 | Write-Verbose $LocalizedData.RegisterServer 95 | Start-OBRegistration -VaultCredentials $VaultCredential -Confirm:$false 96 | Write-Verbose $LocalizedData.RegisteredServer 97 | } else { 98 | Write-Verbose $localizedData.AbsentNotImplemented 99 | } 100 | } 101 | catch { 102 | $exception = $_ 103 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 104 | while ($exception.InnerException -ne $null) 105 | { 106 | $exception = $exception.InnerException 107 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 108 | } 109 | } 110 | } 111 | 112 | function Test-TargetResource 113 | { 114 | [OutputType([boolean])] 115 | param ( 116 | [Parameter(Mandatory)] 117 | [String] $VaultCredential, 118 | 119 | [Parameter()] 120 | [ValidateSet('Present','Absent')] 121 | [String] $Ensure = 'Present' 122 | ) 123 | 124 | try { 125 | $env:PSModulePath += ";$([System.Environment]::GetEnvironmentVariable("PSModulePath","Machine"))" 126 | Import-Module -Name MSOnlineBackup 127 | } 128 | 129 | catch { 130 | throw $localizedData.MSOnlineBackupNotFound 131 | } 132 | 133 | try { 134 | $RegistrationStatus = [Microsoft.Internal.CloudBackup.Client.Common.CBClientCommon]::GetMachineRegistrationStatus($true) 135 | 136 | if ($Ensure -eq 'Present') { 137 | if ($RegistrationStatus) { 138 | Write-Verbose ($localizedData.RegistrationExistsNoAction) 139 | return $true 140 | } else { 141 | Write-Verbose ($localizedData.RegistrationNotFoundShouldAdd) 142 | return $false 143 | } 144 | } else { 145 | if ($RegistrationStatus) { 146 | Write-Verbose ($localizedData.RegistartionExistsShouldDelete) 147 | return $false 148 | } else { 149 | Write-Verbose ($localizedData.RegistrationNotFoundNoAction) 150 | return $true 151 | } 152 | } 153 | } 154 | 155 | catch { 156 | $exception = $_ 157 | Write-Verbose ($LocalizedData.AnErrorOccurred -f $exception.message) 158 | while ($exception.InnerException -ne $null) 159 | { 160 | $exception = $exception.InnerException 161 | Write-Verbose ($LocalizedData.InnerException -f $exception.message) 162 | } 163 | } 164 | } -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSRegistration/cMARSRegistration.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMicrosoftAzureRecoveryServices/DSCResources/cMARSRegistration/cMARSRegistration.schema.mof -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/DSCResources/cMARSRegistration/en-US/cMARSRegistration.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | AlreadyRegistered=Already Registered with an Azure Backup Vault. 3 | NotRegistered=Not registered with an Azure Backup Vault 4 | ProxySettingNotFound=Found no ProxySetting configuration. 5 | MSOnlineBackupNotFound=MSonlineBackup module not found. 6 | RegisterServer=Server will be registered with Azure Backup Vault. 7 | RegisteredServer=Server registration complete. 8 | AbsentNotImplemented=Absent not implemented. Please use cMARSAgentInstall to uninstall the agent. 9 | RegistrationExistsNoAction=Registration Already exists. No Action needed. 10 | RegistrationNotFoundShouldAdd=Registration does not exist. Server will be registered. 11 | RegistartionExistsShouldDelete=Registration already exists. It should be removed. 12 | RegistrationNotFoundNoAction=Registration does not exist. No action needed. 13 | AnErrorOccurred=An error occurred while verifying/updating proxy configuration: {0}. 14 | InnerException=Nested error trying to verifying/updating proxy configuration: {0}. 15 | '@ 16 | -------------------------------------------------------------------------------- /cMicrosoftAzureRecoveryServices/cMicrosoftAzureRecoveryServices.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cMicrosoftAzureRecoveryServices/cMicrosoftAzureRecoveryServices.psd1 -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIActiveScriptConsumer/cWMIActiveScriptConsumer.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingConsumerInstance=Getting Consumer Instance named {0}. 7 | ConsumerInstanceFound=Consumer Instance named {0} is found. 8 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 9 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 10 | NotAbsolutePath=ScriptFileName value {0} provided is not absolte path. 11 | CreatedConsumerInstance=Created Consumer Instance named {0}. 12 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 13 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 14 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 15 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 16 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 17 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 18 | '@ 19 | } 20 | 21 | if (Test-Path "$PSScriptRoot\$PSUICulture") 22 | { 23 | Import-LocalizedData LocalizedData -filename WMIActiveScriptConsumer.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 24 | } 25 | 26 | function Get-TargetResource 27 | { 28 | [CmdletBinding(DefaultParameterSetName='ScriptText')] 29 | [OutputType([Hashtable])] 30 | param ( 31 | [Parameter(Mandatory, ParameterSetName='ScriptText')] 32 | [Parameter(Mandatory, ParameterSetName='ScriptFile')] 33 | [string] $Name, 34 | 35 | [Parameter(Mandatory, ParameterSetName='ScriptFile')] 36 | [String] $ScriptFileName, 37 | 38 | [Parameter(Mandatory, ParameterSetName='ScriptText')] 39 | [String] $ScriptText 40 | ) 41 | 42 | $Configuration = @{ 43 | Name = $Name 44 | } 45 | 46 | if ($PSCmdlet.ParameterSetName -eq 'ScriptText') { 47 | $Configuration.Add('ScriptText', $ScriptText) 48 | } else { 49 | $Configuration.Add('ScriptFileName', $ScriptFileName) 50 | } 51 | 52 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 53 | $ActiveScriptEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM ActiveScriptEventConsumer WHERE Name='$Name'" 54 | 55 | if ($ActiveScriptEventConsumer) { 56 | Write-Verbose ($localizedData.ConsumerInstanceFound -f $Name) 57 | $Configuration.Add('Ensure','Present') 58 | $Configuration.Add('MaximumQueueSize',$ActiveScriptEventConsumer.MaximumQueueSize) 59 | $Configuration.Add('MachineName',$ActiveScriptEventConsumer.MachineName) 60 | $Configuration.Add('CreatorSID',$ActiveScriptEventConsumer.CreatorSID) 61 | } else { 62 | Write-Verbose ($localizedData.ConsumerInstanceNotFound -f $Name) 63 | $Configuration.Add('Ensure','Absent') 64 | } 65 | 66 | return $Configuration 67 | } 68 | 69 | function Set-TargetResource 70 | { 71 | [CmdletBinding(DefaultParameterSetName='ScriptText')] 72 | param ( 73 | [Parameter(Mandatory, ParameterSetName='ScriptText')] 74 | [Parameter(Mandatory, ParameterSetName='ScriptFile')] 75 | [string] $Name, 76 | 77 | [Parameter(Mandatory, ParameterSetName='ScriptFile')] 78 | [String] $ScriptFileName, 79 | 80 | [Parameter(ParameterSetName='ScriptFile')] 81 | [Parameter(ParameterSetName='ScriptText')] 82 | [String] $ScriptingEngine='VBScript', 83 | 84 | [Parameter(Mandatory,ParameterSetName='ScriptText')] 85 | [String] $ScriptText, 86 | 87 | [Parameter(ParameterSetName='ScriptFile')] 88 | [Parameter(ParameterSetName='ScriptText')] 89 | [uint32] $MaximumQueueSize, 90 | 91 | [Parameter(ParameterSetName='ScriptFile')] 92 | [Parameter(ParameterSetName='ScriptText')] 93 | [ValidateSet('Present','Absent')] 94 | [string] 95 | $Ensure = 'Present' 96 | ) 97 | 98 | if ($Ensure -eq 'Present') { 99 | Write-Verbose ($localizedData.CreatingConsumerInstance -f $Name) 100 | 101 | $Properties = @{ 102 | Name = $Name 103 | ScriptingEngine = $ScriptingEngine 104 | } 105 | 106 | if ($PSCmdlet.ParameterSetName -eq 'ScriptFile') { 107 | if (-not [System.IO.Path]::IsPathRooted($ScriptFileName)) { 108 | Throw ($localizedData.NotAbsolutePath -f $ScriptFileName) 109 | } 110 | $Properties.Add('ScriptFileName', $ScriptFileName) 111 | } else { 112 | $Properties.Add('ScriptText', $ScriptText) 113 | } 114 | 115 | if ($MaximumQueueSize) { 116 | $Properties.Add('MaximumQueueSize',$MaximumQueueSize) 117 | } 118 | 119 | New-CimInstance -Namespace 'root\subscription' -ClassName 'ActiveScriptEventConsumer' -Property $Properties 120 | Write-Verbose ($localizedData.CreatedConsumerInstance -f $Name) 121 | } else { 122 | Write-Verbose ($localizedData.RemovingConsumerInstance -f $Name) 123 | Remove-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM ActiveScriptEventConsumer WHERE Name='$Name'" 124 | Write-Verbose ($localizedData.RemovedConsumerInstance -f $Name) 125 | } 126 | } 127 | 128 | function Test-TargetResource 129 | { 130 | [CmdletBinding(DefaultParameterSetName='ScriptText')] 131 | [OutputType([Bool])] 132 | param ( 133 | [Parameter(Mandatory, ParameterSetName='ScriptText')] 134 | [Parameter(Mandatory, ParameterSetName='ScriptFile')] 135 | [string] $Name, 136 | 137 | [Parameter(Mandatory, ParameterSetName='ScriptFile')] 138 | [String] $ScriptFileName, 139 | 140 | [Parameter(ParameterSetName='ScriptFile')] 141 | [Parameter(ParameterSetName='ScriptText')] 142 | [String] $ScriptingEngine='VBScript', 143 | 144 | [Parameter(Mandatory,ParameterSetName='ScriptText')] 145 | [String] $ScriptText, 146 | 147 | [Parameter(ParameterSetName='ScriptFile')] 148 | [Parameter(ParameterSetName='ScriptText')] 149 | [uint32] $MaximumQueueSize, 150 | 151 | [Parameter()] 152 | [Parameter(ParameterSetName='ScriptFile')] 153 | [Parameter(ParameterSetName='ScriptText')] 154 | [ValidateSet('Present','Absent')] 155 | [string] 156 | $Ensure = 'Present' 157 | ) 158 | 159 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 160 | $ActiveScriptEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM ActiveScriptEventConsumer WHERE Name='$Name'" 161 | 162 | if ($Ensure -eq 'Present') { 163 | if ($ActiveScriptEventConsumer) { 164 | Write-Verbose ($localizedData.ConsumerExistsNoAction -f $Name) 165 | return $true 166 | } else { 167 | Write-Verbose ($localizedData.ConsumerDoesNotExistShouldCreate -f $Name) 168 | return $false 169 | } 170 | } else { 171 | if ($ActiveScriptEventConsumer) { 172 | Write-Verbose ($localizedData.ConsumerExistsShouldRemove -f $Name) 173 | return $false 174 | } else { 175 | Write-Verbose ($localizedData.ConsumerDoesNotExistNoAction -f $Name) 176 | return $true 177 | } 178 | } 179 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIActiveScriptConsumer/cWMIActiveScriptConsumer.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMIActiveScriptConsumer")] 2 | class cWMIActiveScriptConsumer : OMI_BaseResource 3 | { 4 | [Key] string Name; 5 | [Write] string ScriptFileName; 6 | [Write] string ScriptText; 7 | [Write] string ScriptingEngine; 8 | [Write] uint32 MaximumQueueSize; 9 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 10 | }; -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIActiveScriptConsumer/en-US/cWMIActiveScriptConsumer.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingConsumerInstance=Getting Consumer Instance named {0}. 3 | ConsumerInstanceFound=Consumer Instance named {0} is found. 4 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 5 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 6 | NotAbsolutePath=ScriptFileName value {0} provided is not absolte path. 7 | CreatedConsumerInstance=Created Consumer Instance named {0}. 8 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 9 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 10 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 11 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 12 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 13 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 14 | '@ 15 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMICommandLineConsumer/cWMICommandLineConsumer.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingConsumerInstance=Getting Consumer Instance named {0}. 7 | ConsumerInstanceFound=Consumer Instance named {0} is found. 8 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 9 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 10 | NotAbsolutePath=ExecutablePath value {0} provided is not absolte path. 11 | CreatedConsumerInstance=Created Consumer Instance named {0}. 12 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 13 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 14 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 15 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 16 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 17 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 18 | '@ 19 | } 20 | 21 | if (Test-Path "$PSScriptRoot\$PSUICulture") 22 | { 23 | Import-LocalizedData LocalizedData -filename WMICommandLineConsumer.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 24 | } 25 | 26 | function Get-TargetResource 27 | { 28 | [CmdletBinding()] 29 | [OutputType([Hashtable])] 30 | param ( 31 | [Parameter(Mandatory)] 32 | [string] $Name, 33 | 34 | [Parameter(Mandatory)] 35 | [String] $CommandLineTemplate, 36 | 37 | [Parameter()] 38 | [String] $ExecutablePath, 39 | 40 | [Parameter()] 41 | [String] $WorkingDirectory 42 | ) 43 | 44 | $Configuration = @{ 45 | Name = $Name 46 | CommandLineTemplate = $CommandLineTemplate 47 | } 48 | 49 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 50 | $ScriptConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM CommandLineEventConsumer WHERE Name='$Name'" 51 | 52 | if ($ScriptConsumer) { 53 | Write-Verbose ($localizedData.ConsumerInstanceFound -f $Name) 54 | $Configuration.Add('Ensure','Present') 55 | $Configuration.Add('ExecutablePath',$CommandLineEventConsumer.ExecutablePath) 56 | $Configuration.Add('WorkingDirectory',$CommandLineEventConsumer.WorkingDirectory) 57 | } else { 58 | Write-Verbose ($localizedData.ConsumerInstanceNotFound -f $Name) 59 | $Configuration.Add('Ensure','Absent') 60 | } 61 | 62 | return $Configuration 63 | } 64 | 65 | function Set-TargetResource 66 | { 67 | [CmdletBinding()] 68 | param ( 69 | [Parameter(Mandatory)] 70 | [string] $Name, 71 | 72 | [Parameter(Mandatory)] 73 | [String] $CommandLineTemplate, 74 | 75 | [Parameter()] 76 | [String] $ExecutablePath, 77 | 78 | [Parameter()] 79 | [String] $WorkingDirectory, 80 | 81 | [Parameter()] 82 | [ValidateSet('Present','Absent')] 83 | [string] 84 | $Ensure = 'Present' 85 | ) 86 | 87 | if ($Ensure -eq 'Present') { 88 | Write-Verbose ($localizedData.CreatingConsumerInstance -f $Name) 89 | 90 | $Properties = @{ 91 | Name = $Name 92 | CommandLineTemplate = $CommandLineTemplate 93 | } 94 | 95 | if ($ExecutablePath) { 96 | if (-not [System.IO.Path]::IsPathRooted($ExecutablePath)) { 97 | Throw ($localizedData.NotAbsolutePath -f $ExecutablePath) 98 | } else { 99 | $Properties.Add('ExecutablePath', $ExecutablePath) 100 | } 101 | } 102 | 103 | if ($WorkingDirectory) { 104 | $Properties.Add('WorkingDirectory',$WorkingDirectory) 105 | } 106 | 107 | New-CimInstance -Namespace 'root\subscription' -ClassName 'CommandLineEventConsumer' -Property $Properties 108 | Write-Verbose ($localizedData.CreatedConsumerInstance -f $Name) 109 | } else { 110 | Write-Verbose ($localizedData.RemovingConsumerInstance -f $Name) 111 | Remove-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM CommandLineEventConsumer WHERE Name='$Name'" 112 | Write-Verbose ($localizedData.RemovedConsumerInstance -f $Name) 113 | } 114 | } 115 | 116 | function Test-TargetResource 117 | { 118 | [CmdletBinding()] 119 | [OutputType([Bool])] 120 | param ( 121 | [Parameter(Mandatory)] 122 | [string] $Name, 123 | 124 | [Parameter(Mandatory)] 125 | [String] $CommandLineTemplate, 126 | 127 | [Parameter()] 128 | [String] $ExecutablePath, 129 | 130 | [Parameter()] 131 | [String] $WorkingDirectory, 132 | 133 | [Parameter()] 134 | [ValidateSet('Present','Absent')] 135 | [string] 136 | $Ensure = 'Present' 137 | ) 138 | 139 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 140 | $CommandLineEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM CommandLineEventConsumer WHERE Name='$Name'" 141 | 142 | if ($Ensure -eq 'Present') { 143 | if ($CommandLineEventConsumer) { 144 | Write-Verbose ($localizedData.ConsumerExistsNoAction -f $Name) 145 | return $true 146 | } else { 147 | Write-Verbose ($localizedData.ConsumerDoesNotExistShouldCreate -f $Name) 148 | return $false 149 | } 150 | } else { 151 | if ($CommandLineEventConsumer) { 152 | Write-Verbose ($localizedData.ConsumerExistsShouldRemove -f $Name) 153 | return $false 154 | } else { 155 | Write-Verbose ($localizedData.ConsumerDoesNotExistNoAction -f $Name) 156 | return $true 157 | } 158 | } 159 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMICommandLineConsumer/cWMICommandLineConsumer.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMICommandLineConsumer")] 2 | class cWMICommandLineConsumer : OMI_BaseResource 3 | { 4 | [Key] string Name; 5 | [Required] string CommandLineTemplate; 6 | [Write] string ExecutablePath; 7 | [Write] string WorkingDirectory; 8 | [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMICommandLineConsumer/en-US/cWMICommandLineConsumer.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingConsumerInstance=Getting Consumer Instance named {0}. 3 | ConsumerInstanceFound=Consumer Instance named {0} is found. 4 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 5 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 6 | NotAbsolutePath=ExecutablePath value {0} provided is not absolte path. 7 | CreatedConsumerInstance=Created Consumer Instance named {0}. 8 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 9 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 10 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 11 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 12 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 13 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 14 | '@ 15 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventBinding/cWMIEventBinding.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingFilterToConsumerBinding="Retreiving any avilable bindings for {0} and {1} of type {2}". 7 | BindingFound="Binding found for filter {0}, consumer {1} of type {2}". 8 | BindingNotFound="Binding found for filter {0}, consumer {1} of type {2}". 9 | GettingFilterAndConsumer="Retrieving Filter and Consumer instances for {0} and {1}". 10 | FilterAndConsumerCannotBeCreated="Filter and Consumer instances cannot be created for filter {0} and consumer {1}". 11 | CreatingFilterToConsumerBinding="Creating event binding for filter {0} and consumer {1} of type {2}". 12 | CreatedEventBinding="Created event binding for filter {0} and consumer {1} of type {2}". 13 | RemovingEventBinding="Removing event binding for filter {0} and consumer {1} of type {2}". 14 | RemovedEventBinding="Removed event binding for filter {0} and consumer {1} of type {2}". 15 | EventBindingExistsNoAction="Event binding for filter {0} and consumer {1} of type {2} exists. No action needed.". 16 | EventBindingDoesNotExistShouldCreate="Event binding for filter {0} and consumer {1} of type {2} does not exist. It will be created". 17 | EventBindingExistsShouldDelete="Event binding for filter {0} and consumer {1} of type {2} exits. It should be deleted". 18 | EventBindingDoesNotExistNoAction="Event binding for filter {0} and consumer {1} of type {2} does not exist. No action needed". 19 | '@ 20 | } 21 | 22 | if (Test-Path "$PSScriptRoot\$PSUICulture") 23 | { 24 | Import-LocalizedData LocalizedData -filename WMIEventBinding.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 25 | } 26 | 27 | $ConsumerHash = @{ 28 | LogFile = 'LogFileEventConsumer' 29 | EventLog = 'NTEventLogEventConsumer' 30 | CommandLine = 'CommandLineEventConsumer' 31 | Script = 'ActiveScriptEventConsumer' 32 | SMTP = 'SMTPEventConsumer' 33 | } 34 | 35 | $DeliveryQoSHash = @{ 36 | Synchronous = 0 37 | Express = 1 38 | } 39 | 40 | function Get-TargetResource 41 | { 42 | [CmdletBinding()] 43 | [OutputType([Hashtable])] 44 | param ( 45 | [Parameter(Mandatory)] 46 | [String] $Filter, 47 | 48 | [Parameter(Mandatory)] 49 | [String] $Consumer, 50 | 51 | [Parameter(Mandatory)] 52 | [ValidateSet('LogFile','EventLog','CommandLine','Script','SMTP')] 53 | [String] $ConsumerType 54 | ) 55 | 56 | $Configuration = @{ 57 | Filter = $Filter 58 | Consumer = $Consumer 59 | } 60 | 61 | Write-Verbose ($localizedData.GettingFilterToConsumerBinding -f $Filter, $Consumer, $ConsumerType) 62 | $Binding = Get-CimInstance -Namespace 'root\subscription' -ClassName __FilterToConsumerBinding | Where-Object { ($_.Filter.Name -eq $Filter) -and ($_.Consumer.Name -eq $Consumer) } 63 | 64 | if ($Binding) { 65 | Write-Verbose ($localizedData.BindingFound -f $Filter, $Consumer, $ConsumerType) 66 | $Configuration.Add('ConsumerType',$Binding.Consumer.CimClass.CimClassName) 67 | $Configuration.Add('Ensure','Present') 68 | } else { 69 | Write-Verbose ($localizedData.BindingNotFound -f $Filter, $Consumer, $ConsumerType) 70 | $Configuration.Add('Ensure','Absent') 71 | } 72 | 73 | $Configuration 74 | } 75 | 76 | function Set-TargetResource 77 | { 78 | [CmdletBinding()] 79 | param ( 80 | [Parameter(Mandatory)] 81 | [String] $Filter, 82 | 83 | [Parameter(Mandatory)] 84 | [String] $Consumer, 85 | 86 | [Parameter(Mandatory)] 87 | [ValidateSet('LogFile','EventLog','CommandLine','Script','SMTP')] 88 | [String] $ConsumerType, 89 | 90 | [Parameter()] 91 | [Boolean] $MaintainSecurityContext = $false, 92 | 93 | [Parameter()] 94 | [Boolean] $SlowDownProviders = $false, 95 | 96 | [Parameter()] 97 | [ValidateSet('Synchronous', 'Express')] 98 | [string] $DeliveryQoS, 99 | 100 | [Parameter()] 101 | [ValidateSet('Present','Absent')] 102 | [String] $Ensure = 'Present' 103 | ) 104 | 105 | if ($Ensure -eq 'Present') { 106 | Write-Verbose ($localizedData.GettingFilterAndConsumer -f $Filter, $Consumer) 107 | 108 | try { 109 | $FilterObject = Get-CimInstance -ClassName '__EventFilter' -Namespace 'root\subscription' -Filter "Name='${filter}'" 110 | $ConsumerObject = Get-CimInstance -ClassName $ConsumerHash[$ConsumerType] -Namespace 'root\subscription' -Filter "Name='${Consumer}'" 111 | } 112 | catch { 113 | throw ($localizedData.FilterAndConsumerCannotBeCreated -f $Filter, $Consumer, $ConsumerType) 114 | } 115 | 116 | $BinderHash = @{ 117 | Filter = [ref]$FilterObject 118 | Consumer = [ref]$ConsumerObject 119 | MaintainSecurityContext = $MaintainSecurityContext 120 | SlowDownProviders = $SlowDownProviders 121 | } 122 | 123 | if ($DeliveryQoS) { 124 | $BinderHash.Add('DeliveryQoS', [uint32]($DeliveryQoSHash[$DeliveryQoS])) 125 | } 126 | 127 | Write-Verbose ($localizedData.CreatingFilterToConsumerBinding -f $Filter, $Consumer, $ConsumerType) 128 | New-CimInstance -ClassName '__FilterToConsumerBinding' -Namespace 'root\subscription' -Property $BinderHash 129 | Write-Verbose ($localizedData.CreatedEventBinding -f $Filter, $Consumer, $ConsumerType) 130 | } else { 131 | Write-Verbose ($localizedData.RemovingEventBinding -f $Filter, $Consumer, $ConsumerType) 132 | $binding = Get-CimInstance -Namespace 'root\subscription' -ClassName __FilterToConsumerBinding | Where-Object { ($_.Filter.Name -eq $Filter) -and ($_.Consumer.Name -eq $Consumer) } 133 | Remove-CimInstance -InputObject $binding 134 | Write-Verbose ($localizedData.RemovedEventBinding -f $Filter, $Consumer, $ConsumerType) 135 | } 136 | } 137 | 138 | function Test-TargetResource 139 | { 140 | [CmdletBinding()] 141 | [OutputType([boolean])] 142 | param ( 143 | [Parameter(Mandatory)] 144 | [String] $Filter, 145 | 146 | [Parameter(Mandatory)] 147 | [String] $Consumer, 148 | 149 | [Parameter(Mandatory)] 150 | [ValidateSet('LogFile','EventLog','CommandLine','Script','SMTP')] 151 | [String] $ConsumerType, 152 | 153 | [Parameter()] 154 | [Boolean] $MaintainSecurityContext = $false, 155 | 156 | [Parameter()] 157 | [Boolean] $SlowDownProviders = $false, 158 | 159 | [Parameter()] 160 | [ValidateSet('Synchronous', 'Express')] 161 | [string] $DeliveryQoS, 162 | 163 | [Parameter()] 164 | [ValidateSet('Present','Absent')] 165 | [String] $Ensure = 'Present' 166 | ) 167 | 168 | Write-Verbose ($localizedData.GettingFilterToConsumerBinding -f $Filter, $Consumer, $ConsumerType) 169 | $binding = Get-CimInstance -Namespace 'root\subscription' -ClassName __FilterToConsumerBinding | Where-Object { ($_.Filter.Name -eq $Filter) -and ($_.Consumer.Name -eq $Consumer) } 170 | 171 | if ($Ensure -eq 'Present') { 172 | if ($binding) { 173 | Write-Verbose ($localizedData.EventBindingExistsNoAction -f $Filter, $Consumer, $ConsumerType) 174 | return $true 175 | } else { 176 | Write-Verbose ($localizedData.EventBindingDoesNotExistShouldCreate -f $Filter, $Consumer, $ConsumerType) 177 | return $false 178 | } 179 | } else { 180 | if ($binding) { 181 | Write-Verbose ($localizedData.EventBindingExistsShouldDelete -f $Filter, $Consumer, $ConsumerType) 182 | return $false 183 | } else { 184 | Write-Verbose ($localizedData.EventBindingDoesNotExistNoAction -f $Filter, $Consumer, $ConsumerType) 185 | return $true 186 | } 187 | } 188 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventBinding/cWMIEventBinding.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMIEventBinding")] 2 | class cWMIEventBinding : OMI_BaseResource 3 | { 4 | [Key] string Filter; 5 | [Key] string Consumer; 6 | [Write] Boolean SlowDownProviders; 7 | [Write] Boolean MaintainSecurityContext; 8 | [Write] uint32 DeliveryQoS; 9 | [Required, ValueMap{"LogFile", "EventLog","CommandLine","Script","SMTP"},Values{"LogFile", "EventLog","CommandLine","Script","SMTP"}] string ConsumerType; 10 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 11 | }; -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventBinding/en-US/cWMIEventBinding.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingFilterToConsumerBinding="Retreiving any avilable bindings for {0} and {1} of type {2}". 3 | BindingFound="Binding found for filter {0}, consumer {1} of type {2}". 4 | BindingNotFound="Binding found for filter {0}, consumer {1} of type {2}". 5 | GettingFilterAndConsumer="Retrieving Filter and Consumer instances for {0} and {1}". 6 | FilterAndConsumerCannotBeCreated="Filter and Consumer instances cannot be created for filter {0} and consumer {1}". 7 | CreatingFilterToConsumerBinding="Creating event binding for filter {0} and consumer {1} of type {2}". 8 | CreatedEventBinding="Created event binding for filter {0} and consumer {1} of type {2}". 9 | RemovingEventBinding="Removing event binding for filter {0} and consumer {1} of type {2}". 10 | RemovedEventBinding="Removed event binding for filter {0} and consumer {1} of type {2}". 11 | EventBindingExistsNoAction="Event binding for filter {0} and consumer {1} of type {2} exists. No action needed.". 12 | EventBindingDoesNotExistShouldCreate="Event binding for filter {0} and consumer {1} of type {2} does not exist. It will be created". 13 | EventBindingExistsShouldDelete="Event binding for filter {0} and consumer {1} of type {2} exits. It should be deleted". 14 | EventBindingDoesNotExistNoAction="Event binding for filter {0} and consumer {1} of type {2} does not exist. No action needed". 15 | '@ 16 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventFilter/cWMIEventFilter.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingFilterInstance=Getting Filter Instance named {0}. 7 | FilterInstanceFound=Filter Instance named {0} is found. 8 | FilterInstanceNotFound=Filter Instance named {0} not found. 9 | CreatingEventFilter=Creating Filter Instance named {0} with query {1}. 10 | CreatedEventFilter=Created Filter Instance named {0}. 11 | RemovingEventFilter=Removing Filter Instance named {0}. 12 | RemovedEventFilter=Removed Filter Instance named {0}. 13 | FilterInstanceFoundNoAction=Filter Instance named {0} already exists. No action needed. 14 | FilterInstanceNotFoundShouldCreate=Filter Instance named {0} does not exist. It will be created. 15 | FilterInstanceFoundShouldDelete=Filter Instance named {0} exists. This will be removed. 16 | FilterInstanceNotFoundNoAction=Filter Instance named {0} not found. No action needed. 17 | '@ 18 | } 19 | 20 | if (Test-Path "$PSScriptRoot\$PSUICulture") 21 | { 22 | Import-LocalizedData LocalizedData -filename WMIEventFilter.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 23 | } 24 | 25 | function Get-TargetResource 26 | { 27 | [CmdletBinding()] 28 | [OutputType([Hashtable])] 29 | param ( 30 | [Parameter(Mandatory)] 31 | [String] $Name, 32 | 33 | [Parameter(Mandatory)] 34 | [String] $Query, 35 | 36 | [Parameter()] 37 | [String] $EventNamespace='root\cimv2' 38 | ) 39 | 40 | $Configuration = @{ 41 | Name = $Name 42 | EventNamespace = $EventNamespace 43 | } 44 | 45 | Write-Verbose ($localizedData.GettingFilterInstance -f $Name) 46 | $EventFilter = Get-CimInstance -Namespace 'root\subscription' -Class __EventFilter -Filter "Name='$Name'" 47 | if ($EventFilter) { 48 | Write-Verbose ($localizedData.FilterInstanceFound -f $Name) 49 | $Configuration.Add('Ensure','Present') 50 | $Configuration.Add('Query',$EventFilter.Query) 51 | } else { 52 | Write-Verbose ($localizedData.FilterInstanceNotFound -f $Name) 53 | $Configuration.Add('Ensure','Absent') 54 | } 55 | 56 | return $Configuration 57 | } 58 | 59 | function Set-TargetResource 60 | { 61 | [CmdletBinding()] 62 | param ( 63 | [Parameter(Mandatory)] 64 | [String] $Name, 65 | 66 | [Parameter(Mandatory)] 67 | [String] $Query, 68 | 69 | [Parameter()] 70 | [String] $EventNamespace='root\cimv2', 71 | 72 | [Parameter()] 73 | [ValidateSet('Present','Absent')] 74 | [string] 75 | $Ensure = 'Present' 76 | ) 77 | 78 | if ($Ensure -eq 'Present') { 79 | Write-Verbose ($localizedData.CreatingEventFilter -f $Name, $Query) 80 | New-CimInstance -ClassName '__EventFilter' -Namespace 'root\subscription' -Property @{ 81 | Name = $Name 82 | EventNamespace = $EventNamespace 83 | Query = $Query 84 | QueryLanguage = 'WQL' 85 | } 86 | Write-Verbose ($localizedData.CreatedEventFilter -f $Name) 87 | } else { 88 | Write-Verbose ($localizedData.RemovingEventFilter -f $Name) 89 | Remove-CimInstance -Namespace 'root\subscription' -Query "Select * FROM __EventFilter WHERE Name='${Name}'" 90 | Write-Verbose ($localizedData.RemovedEventFilter -f $Name) 91 | } 92 | } 93 | 94 | function Test-TargetResource 95 | { 96 | [CmdletBinding()] 97 | [OutputType([boolean])] 98 | param ( 99 | [Parameter(Mandatory)] 100 | [String] $Name, 101 | 102 | [Parameter(Mandatory)] 103 | [String] $Query, 104 | 105 | [Parameter()] 106 | [String] $EventNamespace='root\cimv2', 107 | 108 | [Parameter()] 109 | [ValidateSet('Present','Absent')] 110 | [string] 111 | $Ensure = 'Present' 112 | ) 113 | 114 | Write-Verbose ($localizedData.GettingFilterInstance -f $Name) 115 | $EventFilter = Get-CimInstance -Namespace 'root\subscription' -Class __EventFilter -Filter "Name='$Name'" 116 | 117 | if ($Ensure -eq 'Present') { 118 | if ($EventFilter) { 119 | Write-Verbose ($localizedData.FilterInstanceFoundNoAction -f $Name) 120 | return $true 121 | } else { 122 | Write-Verbose ($localizedData.FilterInstanceNotFoundShouldCreate -f $Name) 123 | return $false 124 | } 125 | } else { 126 | if ($EventFilter) { 127 | Write-Verbose ($localizedData.FilterInstanceFoundShouldDelete -f $Name) 128 | return $false 129 | } else { 130 | Write-Verbose ($localizedData.FilterInstanceNotFoundNoAction -f $Name) 131 | return $true 132 | } 133 | } 134 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventFilter/cWMIEventFilter.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMIEventFilter")] 2 | class cWMIEventFilter : OMI_BaseResource 3 | { 4 | [Key] string Name; 5 | [Required] string Query; 6 | [write] string EventNamespace; 7 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 8 | }; -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventFilter/en-US/cWMIEventFilter.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingFilterInstance=Getting Filter Instance named {0}. 3 | FilterInstanceFound=Filter Instance named {0} is found. 4 | FilterInstanceNotFound=Filter Instance named {0} not found. 5 | CreatingEventFilter=Creating Filter Instance named {0} with query {1}. 6 | CreatedEventFilter=Created Filter Instance named {0}. 7 | RemovingEventFilter=Removing Filter Instance named {0}. 8 | RemovedEventFilter=Removed Filter Instance named {0}. 9 | FilterInstanceFoundNoAction=Filter Instance named {0} already exists. No action needed. 10 | FilterInstanceNotFoundShouldCreate=Filter Instance named {0} does not exist. It will be created. 11 | FilterInstanceFoundShouldDelete=Filter Instance named {0} exists. This will be removed. 12 | FilterInstanceNotFoundNoAction=Filter Instance named {0} not found. No action needed. 13 | '@ 14 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventLogConsumer/cWMIEventLogConsumer.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingConsumerInstance=Getting Consumer Instance named {0}. 7 | ConsumerInstanceFound=Consumer Instance named {0} is found. 8 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 9 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 10 | CreatedConsumerInstance=Created Consumer Instance named {0}. 11 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 12 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 13 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 14 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 15 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 16 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 17 | '@ 18 | } 19 | 20 | if (Test-Path "$PSScriptRoot\$PSUICulture") 21 | { 22 | Import-LocalizedData LocalizedData -filename WMIEventLogConsumer.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 23 | } 24 | 25 | function Get-TargetResource 26 | { 27 | [CmdletBinding()] 28 | [OutputType([Hashtable])] 29 | param ( 30 | [Parameter(Mandatory)] 31 | [string] $Name, 32 | 33 | [Parameter(Mandatory)] 34 | [uint32] $EventID 35 | ) 36 | 37 | $Configuration = @{ 38 | Name = $Name 39 | EventID = $EventID 40 | } 41 | 42 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 43 | $NTEventLogEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM NTEventLogEventConsumer WHERE Name='$Name'" 44 | 45 | if ($NTEventLogEventConsumer) { 46 | Write-Verbose ($localizedData.ConsumerInstanceFound -f $Name) 47 | $Configuration.Add('Ensure','Present') 48 | $Configuration.Add('Category',$NTEventLogEventConsumer.Cateogry) 49 | $Configuration.Add('EventType', $NTEventLogEventConsumer.EventType) 50 | $Configuration.Add('NumberOfInsertionStrings', $NTEventLogEventConsumer.NumberOfInsertionStrings) 51 | $Configuration.Add('SourceName', $NTEventLogEventConsumer.SourceName) 52 | $Configuration.Add('UNCServerName',$NTEventLogEventConsumer.UNCServerName) 53 | $Configuration.Add('InsertionStringTemplates',$NTEventLogEventConsumer.InsertionStringTemplates) 54 | } else { 55 | Write-Verbose ($localizedData.ConsumerInstanceNotFound -f $Name) 56 | $Configuration.Add('Ensure','Absent') 57 | } 58 | 59 | return $Configuration 60 | } 61 | 62 | function Set-TargetResource 63 | { 64 | [CmdletBinding()] 65 | param ( 66 | [Parameter(Mandatory)] 67 | [string] $Name, 68 | 69 | [Parameter(Mandatory)] 70 | [uint32] $EventID, 71 | 72 | [Parameter()] 73 | [uint16] $Category=10, 74 | 75 | [Parameter()] 76 | [ValidateSet('Sucess','Error','Warning','Information','AuditSuccess','AuditFailure')] 77 | [string] $EventType = 'Error', 78 | 79 | [Parameter()] 80 | [uint32] $NumberOfInsertionStrings=1, 81 | 82 | [Parameter()] 83 | [String] $SourceName='PermanentConsumer', 84 | 85 | [Parameter()] 86 | [String] $UNCServerName, 87 | 88 | [Parameter()] 89 | [string[]] $InsertionStringTemplates, 90 | 91 | [Parameter()] 92 | [ValidateSet('Present','Absent')] 93 | [string] 94 | $Ensure = 'Present' 95 | ) 96 | 97 | $EventTypeHash = @{ 98 | Success = 0 99 | Error = 1 100 | Warning = 2 101 | Information = 4 102 | AuditSuccess = 8 103 | AuditFailure = 16 104 | } 105 | 106 | if ($Ensure -eq 'Present') { 107 | Write-Verbose ($localizedData.CreatingConsumerInstance -f $Name) 108 | $Properties = @{ 109 | Name = $Name 110 | Category = $Category 111 | EventID = $EventID 112 | EventType = [uint32]$EventTypeHash[$EventType] 113 | NumberOfInsertionStrings = $NumberOfInsertionStrings 114 | SourceName = $SourceName 115 | } 116 | 117 | if ($UNCServerName) { 118 | $Properties.Add('UNCServerName',$UNCServerName) 119 | } 120 | 121 | if ($InsertionStringTemplates) { 122 | if ($InsertionStringTemplates.Count -gt 1) { 123 | $Properties.Add('InsertionStringTemplates',$InsertionStringTemplates -join ',') 124 | } else { 125 | $Properties.Add('InsertionStringTemplates',$InsertionStringTemplates) 126 | } 127 | } 128 | 129 | New-CimInstance -Namespace 'root\subscription' -ClassName 'NTEventLogEventConsumer' -Property $Properties 130 | Write-Verbose ($localizedData.CreatedConsumerInstance -f $Name) 131 | } else { 132 | Write-Verbose ($localizedData.RemovingConsumerInstance -f $Name) 133 | Remove-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM NTEventLogEventConsumer WHERE Name='$Name'" 134 | Write-Verbose ($localizedData.RemovedConsumerInstance -f $Name) 135 | } 136 | } 137 | 138 | function Test-TargetResource 139 | { 140 | [CmdletBinding()] 141 | [OutputType([Bool])] 142 | param ( 143 | [Parameter(Mandatory)] 144 | [string] $Name, 145 | 146 | [Parameter()] 147 | [uint16] $Category=10, 148 | 149 | [Parameter(Mandatory)] 150 | [uint32] $EventID, 151 | 152 | [Parameter()] 153 | [ValidateSet('Sucess','Error','Warning','Information','AuditSuccess','AuditFailure')] 154 | [string] $EventType = 'Error', 155 | 156 | [Parameter()] 157 | [uint32] $NumberOfInsertionStrings=1, 158 | 159 | [Parameter()] 160 | [String] $SourceName='PermanentConsumer', 161 | 162 | [Parameter()] 163 | [String] $UNCServerName, 164 | 165 | [Parameter()] 166 | [string[]] $InsertionStringTemplates, 167 | 168 | [Parameter()] 169 | [ValidateSet('Present','Absent')] 170 | [string] 171 | $Ensure = 'Present' 172 | ) 173 | 174 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 175 | $NTEventLogEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM NTEventLogEventConsumer WHERE Name='$Name'" 176 | 177 | if ($Ensure -eq 'Present') { 178 | if ($NTEventLogEventConsumer) { 179 | Write-Verbose ($localizedData.ConsumerExistsNoAction -f $Name) 180 | return $true 181 | } else { 182 | Write-Verbose ($localizedData.ConsumerDoesNotExistShouldCreate -f $Name) 183 | return $false 184 | } 185 | } else { 186 | if ($NTEventLogEventConsumer) { 187 | Write-Verbose ($localizedData.ConsumerExistsShouldRemove -f $Name) 188 | return $false 189 | } else { 190 | Write-Verbose ($localizedData.ConsumerDoesNotExistNoAction -f $Name) 191 | return $true 192 | } 193 | } 194 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventLogConsumer/cWMIEventLogConsumer.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMIEventLogConsumer")] 2 | class cWMIEventLogConsumer : OMI_BaseResource 3 | { 4 | [Key] string Name; 5 | [Write] uint16 Category; 6 | [Required] uint32 EventID; 7 | [Write, ValueMap{"Success","Error","Warning","Information","AuditSuccess","AuditFailure"}, Values{"Success","Error","Warning","Information","AuditSuccess","AuditFailure"}] string EventType; 8 | [Write] uint32 NumberOfInsertionStrings; 9 | [Write] string SourceName; 10 | [Write] string UNCServerName; 11 | [Write] string InsertionStringTemplates[]; 12 | [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; 13 | }; -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMIEventLogConsumer/en-US/cWMIEventLogConsumer.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingConsumerInstance=Getting Consumer Instance named {0}. 3 | ConsumerInstanceFound=Consumer Instance named {0} is found. 4 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 5 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 6 | CreatedConsumerInstance=Created Consumer Instance named {0}. 7 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 8 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 9 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 10 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 11 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 12 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 13 | '@ 14 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMILogFileConsumer/cWMILogFileConsumer.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingConsumerInstance=Getting Consumer Instance named {0}. 7 | ConsumerInstanceFound=Consumer Instance named {0} is found. 8 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 9 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 10 | NotAbsolutePath=FileName value {0} provided is not absolte path. It will be converted to absolutepath. 11 | CreatedConsumerInstance=Created Consumer Instance named {0}. 12 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 13 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 14 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 15 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 16 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 17 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 18 | '@ 19 | } 20 | 21 | if (Test-Path "$PSScriptRoot\$PSUICulture") 22 | { 23 | Import-LocalizedData LocalizedData -filename WMILogFileConsumer.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 24 | } 25 | 26 | function Get-TargetResource 27 | { 28 | [CmdletBinding()] 29 | [OutputType([Hashtable])] 30 | param ( 31 | [Parameter(Mandatory)] 32 | [string] $Name, 33 | 34 | [Parameter(Mandatory)] 35 | [String] $Filename, 36 | 37 | [Parameter(Mandatory)] 38 | [String] $Text 39 | ) 40 | 41 | $Configuration = @{ 42 | Name = $Name 43 | Filename = $Filename 44 | Text = $Text 45 | } 46 | 47 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 48 | $LogFileConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM LogFileEventConsumer WHERE Name='$Name'" 49 | 50 | if ($LogFileConsumer) { 51 | Write-Verbose ($localizedData.ConsumerInstanceFound -f $Name) 52 | $Configuration.Add('Ensure','Present') 53 | $Configuration.Add('MaximumFileSize',$LogFileConsumer.MaximumFileSize) 54 | $Configuration.Add('IsUnicode',$LogFileConsumer.IsUnicode) 55 | } else { 56 | Write-Verbose ($localizedData.ConsumerInstanceNotFound -f $Name) 57 | $Configuration.Add('Ensure','Absent') 58 | } 59 | 60 | return $Configuration 61 | } 62 | 63 | function Set-TargetResource 64 | { 65 | [CmdletBinding()] 66 | param ( 67 | [Parameter(Mandatory)] 68 | [string] $Name, 69 | 70 | [Parameter(Mandatory)] 71 | [String] $Filename, 72 | 73 | [Parameter(Mandatory)] 74 | [String] $Text, 75 | 76 | [Parameter()] 77 | [uint64] $MaximumFileSize = 65535, 78 | 79 | [Parameter()] 80 | [Bool] $IsUnicode = $true, 81 | 82 | [Parameter()] 83 | [ValidateSet('Present','Absent')] 84 | [string] 85 | $Ensure = 'Present' 86 | ) 87 | 88 | if ($Ensure -eq 'Present') { 89 | Write-Verbose ($localizedData.CreatingConsumerInstance -f $Name) 90 | 91 | if (-not [System.IO.Path]::IsPathRooted($Filename)) { 92 | $Filename = [System.IO.Path]::GetFullPath($Filename) 93 | Write-Verbose ($localizedData.NotAbsolutePath -f $Filename) 94 | } 95 | 96 | New-CimInstance -Namespace 'root\subscription' -ClassName 'LogFileEventConsumer' -Property @{ 97 | Name = $Name 98 | FileName = $Filename 99 | Text = $Text 100 | MaximumFileSize = $MaximumFileSize 101 | IsUnicode = $IsUnicode 102 | } 103 | Write-Verbose ($localizedData.CreatedConsumerInstance -f $Name) 104 | } else { 105 | Write-Verbose ($localizedData.RemovingConsumerInstance -f $Name) 106 | Remove-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM LogFileEventConsumer WHERE Name='$Name'" 107 | Write-Verbose ($localizedData.RemovedConsumerInstance -f $Name) 108 | } 109 | } 110 | 111 | function Test-TargetResource 112 | { 113 | [CmdletBinding()] 114 | [OutputType([Bool])] 115 | param ( 116 | [Parameter(Mandatory)] 117 | [string] $Name, 118 | 119 | [Parameter(Mandatory)] 120 | [String] $Filename, 121 | 122 | [Parameter(Mandatory)] 123 | [String] $Text, 124 | 125 | [Parameter()] 126 | [uint64] $MaximumFileSize = 65535, 127 | 128 | [Parameter()] 129 | [Bool] $IsUnicode = $true, 130 | 131 | [Parameter()] 132 | [ValidateSet('Present','Absent')] 133 | [string] 134 | $Ensure = 'Present' 135 | ) 136 | 137 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 138 | $LogFileConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM LogFileEventConsumer WHERE Name='$Name'" 139 | 140 | if ($Ensure -eq 'Present') { 141 | if ($LogFileConsumer) { 142 | Write-Verbose ($localizedData.ConsumerExistsNoAction -f $Name) 143 | return $true 144 | } else { 145 | Write-Verbose ($localizedData.ConsumerDoesNotExistShouldCreate -f $Name) 146 | return $false 147 | } 148 | } else { 149 | if ($LogFileConsumer) { 150 | Write-Verbose ($localizedData.ConsumerExistsShouldRemove -f $Name) 151 | return $false 152 | } else { 153 | Write-Verbose ($localizedData.ConsumerDoesNotExistNoAction -f $Name) 154 | return $true 155 | } 156 | } 157 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMILogFileConsumer/cWMILogFileConsumer.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMILogFileConsumer")] 2 | class cWMILogFileConsumer : OMI_BaseResource 3 | { 4 | [Key] string Name; 5 | [Required] string Filename; 6 | [Required] string Text; 7 | [write] uint64 MaximumFileSize; 8 | [write] boolean IsUnicode; 9 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 10 | }; -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMILogFileConsumer/en-US/cWMILogFileConsumer.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingConsumerInstance=Getting Consumer Instance named {0}. 3 | ConsumerInstanceFound=Consumer Instance named {0} is found. 4 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 5 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 6 | NotAbsolutePath=FileName value {0} provided is not absolte path. It will be converted to absolutepath. 7 | CreatedConsumerInstance=Created Consumer Instance named {0}. 8 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 9 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 10 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 11 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 12 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 13 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 14 | '@ 15 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMISMTPConsumer/cWMISMTPConsumer.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GettingConsumerInstance=Getting Consumer Instance named {0}. 7 | ConsumerInstanceFound=Consumer Instance named {0} is found. 8 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 9 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 10 | CreatedConsumerInstance=Created Consumer Instance named {0}. 11 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 12 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 13 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 14 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 15 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 16 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 17 | '@ 18 | } 19 | 20 | if (Test-Path "$PSScriptRoot\$PSUICulture") 21 | { 22 | Import-LocalizedData LocalizedData -filename WMISMTPConsumer.psd1 -baseDirectory "$PSScriptRoot\$PSUICulture" 23 | } 24 | 25 | function Get-TargetResource 26 | { 27 | [CmdletBinding()] 28 | [OutputType([Hashtable])] 29 | param ( 30 | [Parameter(Mandatory)] 31 | [string] $Name, 32 | 33 | [Parameter(Mandatory)] 34 | [String] $ToLine, 35 | 36 | [Parameter(Mandatory)] 37 | [String] $FromLine, 38 | 39 | [Parameter(Mandatory)] 40 | [String] $SMTPServer, 41 | 42 | [Parameter()] 43 | [String] $Message, 44 | 45 | [Parameter()] 46 | [String] $Subject, 47 | 48 | [Parameter()] 49 | [String] $CcLine, 50 | 51 | [Parameter()] 52 | [String] $BccLine, 53 | 54 | [Parameter()] 55 | [String] $ReplyToLine 56 | ) 57 | 58 | $Configuration = @{ 59 | Name = $Name 60 | ToLine = $ToLine 61 | FromLine = $FromLine 62 | SMTPServer = $SMTPServer 63 | } 64 | 65 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 66 | $SMTPEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM SMTPEventConsumer WHERE Name='$Name'" 67 | if ($SMTPEventConsumer) { 68 | Write-Verbose ($localizedData.ConsumerInstanceFound -f $Name) 69 | $Configuration.Add('Ensure','Present') 70 | $Configuration.Add('Message',$SMTPEventConsumer.Message) 71 | $Configuration.Add('Subject',$SMTPEventConsumer.Subject) 72 | $Configuration.Add('CcLine',$SMTPEventConsumer.CcLine) 73 | $Configuration.Add('BccLine',$SMTPEventConsumer.CcLine) 74 | $Configuration.Add('ReplyToLine',$SMTPEventConsumer.CcLine) 75 | } else { 76 | Write-Verbose ($localizedData.ConsumerInstanceNotFound -f $Name) 77 | $Configuration.Add('Ensure','Absent') 78 | } 79 | 80 | return $Configuration 81 | } 82 | 83 | function Set-TargetResource 84 | { 85 | [CmdletBinding()] 86 | param ( 87 | [Parameter(Mandatory)] 88 | [string] $Name, 89 | 90 | [Parameter(Mandatory)] 91 | [String] $ToLine, 92 | 93 | [Parameter(Mandatory)] 94 | [String] $FromLine, 95 | 96 | [Parameter(Mandatory)] 97 | [String] $SMTPServer, 98 | 99 | [Parameter()] 100 | [String] $Message, 101 | 102 | [Parameter()] 103 | [String] $Subject, 104 | 105 | [Parameter()] 106 | [String] $CcLine, 107 | 108 | [Parameter()] 109 | [String] $BccLine, 110 | 111 | [Parameter()] 112 | [String] $ReplyToLine, 113 | 114 | [Parameter()] 115 | [ValidateSet('Present','Absent')] 116 | [string] 117 | $Ensure = 'Present' 118 | ) 119 | 120 | if ($Ensure -eq 'Present') { 121 | Write-Verbose ($localizedData.CreatingConsumerInstance -f $Name) 122 | $Properties = @{ 123 | Name = $Name 124 | ToLine = $ToLine 125 | FromLine = $FromLine 126 | SMTPServer = $SMTPServer 127 | } 128 | 129 | if ($Message) { 130 | $Properties.Add('Message',$Message) 131 | } 132 | 133 | if ($Subject) { 134 | $Properties.Add('Subject',$Subject) 135 | } 136 | 137 | if ($CcLine) { 138 | $Properties.Add('CcLine',$CcLine) 139 | } 140 | 141 | if ($BccLine) { 142 | $Properties.Add('BccLine',$BccLine) 143 | } 144 | 145 | if ($ReplyToLine) { 146 | $Properties.Add('ReplyToLine',$ReplyToLine) 147 | } 148 | Write-Verbose ($localizedData.CreatedConsumerInstance -f $Name) 149 | New-CimInstance -Namespace 'root\subscription' -ClassName 'SMTPEventConsumer' -Property $Properties 150 | } else { 151 | Write-Verbose ($localizedData.RemovingConsumerInstance -f $Name) 152 | Remove-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM SMTPEventConsumer WHERE Name='$Name'" 153 | Write-Verbose ($localizedData.RemovedConsumerInstance -f $Name) 154 | } 155 | } 156 | 157 | function Test-TargetResource 158 | { 159 | [CmdletBinding()] 160 | [OutputType([Bool])] 161 | param ( 162 | [Parameter(Mandatory)] 163 | [string] $Name, 164 | 165 | [Parameter(Mandatory)] 166 | [String] $ToLine, 167 | 168 | [Parameter(Mandatory)] 169 | [String] $FromLine, 170 | 171 | [Parameter(Mandatory)] 172 | [String] $SMTPServer, 173 | 174 | [Parameter()] 175 | [String] $Message, 176 | 177 | [Parameter()] 178 | [String] $Subject, 179 | 180 | [Parameter()] 181 | [String] $CcLine, 182 | 183 | [Parameter()] 184 | [String] $BccLine, 185 | 186 | [Parameter()] 187 | [String] $ReplyToLine, 188 | 189 | [Parameter()] 190 | [ValidateSet('Present','Absent')] 191 | [string] 192 | $Ensure = 'Present' 193 | ) 194 | 195 | Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) 196 | $SMTPEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM SMTPEventConsumer WHERE Name='$Name'" 197 | 198 | if ($Ensure -eq 'Present') { 199 | if ($SMTPEventConsumer) { 200 | Write-Verbose ($localizedData.ConsumerExistsNoAction -f $Name) 201 | return $true 202 | } else { 203 | Write-Verbose ($localizedData.ConsumerDoesNotExistShouldCreate -f $Name) 204 | return $false 205 | } 206 | } else { 207 | if ($SMTPEventConsumer) { 208 | bose ($localizedData.ConsumerExistsShouldRemove -f $Name) 209 | return $false 210 | } else { 211 | Write-Verbose ($localizedData.ConsumerDoesNotExistNoAction -f $Name) 212 | return $true 213 | } 214 | } 215 | } -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMISMTPConsumer/cWMISMTPConsumer.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0"), FriendlyName("cWMISMTPConsumer")] 2 | class cWMISMTPConsumer : OMI_BaseResource 3 | { 4 | [Key] string Name; 5 | [Required] string ToLine; 6 | [Required] string FromLine; 7 | [Required] string SMTPServer; 8 | [Write] string Message; 9 | [Write] string Subject; 10 | [Write] string CcLine; 11 | [Write] string BccLine; 12 | [Write] string ReplyToLine; 13 | [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; 14 | }; -------------------------------------------------------------------------------- /cWMIPermanentEvents/DSCResources/cWMISMTPConsumer/en-US/cWMISMTPConsumer.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GettingConsumerInstance=Getting Consumer Instance named {0}. 3 | ConsumerInstanceFound=Consumer Instance named {0} is found. 4 | ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. 5 | CreatingConsumerInstance=Creating Consumer Instance named {0}. 6 | CreatedConsumerInstance=Created Consumer Instance named {0}. 7 | RemovingConsumerInstance=Removing Consumer Instance named {0}. 8 | RemovedConsumerInstance=Removed Consumer Instance named {0}. 9 | ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. 10 | ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. 11 | ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. 12 | ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. 13 | '@ 14 | -------------------------------------------------------------------------------- /cWMIPermanentEvents/cWMIPermanentEvents.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cWMIPermanentEvents/cWMIPermanentEvents.psd1 -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cAutoAdminLogon/cAutoAdminLogon.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cWindowsOS/DSCResources/cAutoAdminLogon/cAutoAdminLogon.psd1 -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cAutoAdminLogon/cAutoAdminLogon.schema.psm1: -------------------------------------------------------------------------------- 1 | Configuration cAutoAdminLogon { 2 | Param ( 3 | [Parameter(Mandatory)] 4 | [PSCredential] $AutoAdminCredential, 5 | 6 | [Parameter()] 7 | [ValidateSet("Present","Absent")] 8 | [String]$Ensure = "Present" 9 | ) 10 | 11 | #Get the default domain name from the credential object 12 | if ($AutoAdminCredential.GetNetworkCredential().Domain) { 13 | $DefaultDomainName = $AutoAdminCredential.GetNetworkCredential().Domain 14 | } else { 15 | $DefaultDomainName = "" 16 | } 17 | 18 | Registry DefaultDomainName 19 | { 20 | Ensure = $Ensure 21 | Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 22 | ValueName = 'DefaultDomainName' 23 | ValueData = $DefaultDomainName 24 | } 25 | 26 | Registry DefaultUserName 27 | { 28 | Ensure = $Ensure 29 | Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 30 | ValueName = 'DefaultUserName' 31 | ValueData = $AutoAdminCredential.GetNetworkCredential().UserName 32 | } 33 | 34 | Registry DefaultPassword 35 | { 36 | Ensure = $Ensure 37 | Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 38 | ValueName = 'DefaultPassword' 39 | ValueData = $AutoAdminCredential.GetNetworkCredential().Password 40 | } 41 | 42 | Registry AutoAdminLogon 43 | { 44 | Ensure = $Ensure 45 | Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 46 | ValueName = 'AutoAdminLogon' 47 | ValueData = 1 48 | } 49 | } -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cDiskImage/cDiskImage.psm1: -------------------------------------------------------------------------------- 1 | # Fallback message strings in en-US 2 | DATA localizedData 3 | { 4 | # same as culture = "en-US" 5 | ConvertFrom-StringData @' 6 | GetDiskImage=Getting Disk Image Instance at path {0}. 7 | DiskImageMounted=Disk image at the path {0} is mounted. 8 | DiskImageNotMounted=Disk image at the path {0} is not mounted. 9 | MountingDiskImage=Mounting disk image at path {0}. 10 | MountedDiskImage=Disk image at path {0} is mounted. 11 | SetDriveLetetr=Setting Drive letter of the mounted image to {0}. 12 | DriverLetterSet=Drive letter of the mounted image set to {0}. 13 | DisMountingDiskImage=Dismounting disk image at path {0}. 14 | DismountedDiskImage=Disk image at path {0} is dismounted. 15 | MountExistsWithDriveLetter=Disk image mount exists with same drive letter as requested. 16 | MountExistsWithDifferentDriveLetter=Disk image mount exists with different drive letter than requested. 17 | MountExistsNoAction=Disk image mount for {0} already exists. No action needed. 18 | MountDoesNotExistShouldCreate=Disk image mount for {0} does not exist. It will be mounted. 19 | MountExistsShouldRemove=Disk image mount for {0} exists. It will be dismounted. 20 | MountDoesNotExistNoAction=Disk image mount for {0} does not exist. No action needed. 21 | '@ 22 | } 23 | 24 | if (Test-Path $PSScriptRoot\en-us) 25 | { 26 | Import-LocalizedData LocalizedData -filename cDiskImage.psd1 27 | } 28 | 29 | Function Get-TargetResource { 30 | [OutputType([Hashtable])] 31 | param ( 32 | [Parameter(Mandatory)] 33 | [String] $Id, 34 | 35 | [Parameter(Mandatory)] 36 | [ValidateScript( 37 | { 38 | $extension = [System.IO.Path]::GetExtension($_) 39 | if (($extension -eq '.iso' -or $extension -eq '.vhd' -or $extension -eq '.vhdx') -and (Test-Path $_)) { 40 | $true 41 | } else { 42 | $false 43 | } 44 | } 45 | )] 46 | [string] $ImagePath, 47 | 48 | [Parameter(Mandatory)] 49 | [string] $DriveLetter, 50 | 51 | [Parameter()] 52 | [ValidateSet('Present','Absent')] 53 | [string] $Ensure = 'Present' 54 | ) 55 | 56 | $Configuration = @{ 57 | Id = $Id 58 | ImagePath = $ImagePath 59 | DriveLetter = $DriveLetter 60 | } 61 | 62 | Write-Verbose -Message ($localizedData.GetDiskImage -f $ImagePath) 63 | $DiskImage = Get-DiskImage -ImagePath $ImagePath 64 | if ($DiskImage.Attached) { 65 | if (($DiskImage | Get-Volume).DriveLetter -eq $DriveLetter) { 66 | Write-Verbose -Message ($localizedData.DiskImageMounted -f $ImagePath) 67 | $Configuration.Add('Ensure','Present') 68 | } else { 69 | Write-Verbose -Message ($localizedData.DiskImageNotMounted -f $ImagePath) 70 | $Configuration.Add('Ensure','Absent') 71 | } 72 | } 73 | 74 | $Configuration 75 | } 76 | 77 | 78 | Function Set-TargetResource { 79 | [CmdletBinding()] 80 | param ( 81 | [Parameter(Mandatory)] 82 | [String] $Id, 83 | 84 | [Parameter(Mandatory)] 85 | [ValidateScript( 86 | { 87 | $extension = [System.IO.Path]::GetExtension($_) 88 | if (($extension -eq '.iso' -or $extension -eq '.vhd' -or $extension -eq '.vhdx') -and (Test-Path $_)) { 89 | $true 90 | } else { 91 | $false 92 | } 93 | } 94 | )] 95 | [string] $ImagePath, 96 | 97 | [Parameter(Mandatory)] 98 | [string] $DriveLetter, 99 | 100 | [Parameter()] 101 | [ValidateSet('Present','Absent')] 102 | [string] $Ensure = 'Present' 103 | ) 104 | 105 | $DriveLetter = $DriveLetter + ':' 106 | 107 | if ($Ensure -eq 'Present') { 108 | Write-Verbose -Message ($localizedData.MountingDiskImage -f $ImagePath) 109 | $DiskImage = Mount-DiskImage -ImagePath $ImagePath -NoDriveLetter -PassThru | Get-Volume 110 | Write-Verbose -Message ($localizedData.MountedDiskImage -f $ImagePath) 111 | $DiskVolume = Get-CimInstance -ClassName Win32_Volume | Where-Object { $_.DeviceID -eq $DiskImage.UniqueId } 112 | 113 | Write-Verbose -Message ($localizedData.SetDriveLetter -f $DriveLetter) 114 | Set-CimInstance -Property @{DriveLetter= $DriveLetter } -InputObject $DiskVolume 115 | Write-Verbose -Message ($localizedData.DriveLetterSet -f $DriveLetter) 116 | } else { 117 | Write-Verbose -Message ($localizedData.DisMountingDiskImage -f $DiskImage) 118 | Dismount-DiskImage -ImagePath $ImagePath 119 | Write-Verbose -Message ($localizedData.DismountedDiskImage -f $DiskImage) 120 | } 121 | } 122 | 123 | Function Test-TargetResource { 124 | [CmdletBinding()] 125 | [OutputType([Boolean])] 126 | param ( 127 | [Parameter(Mandatory)] 128 | [String] $Id, 129 | 130 | [Parameter(Mandatory)] 131 | [ValidateScript( 132 | { 133 | $extension = [System.IO.Path]::GetExtension($_) 134 | if (($extension -eq '.iso' -or $extension -eq '.vhd' -or $extension -eq '.vhdx') -and (Test-Path $_)) { 135 | $true 136 | } else { 137 | $false 138 | } 139 | } 140 | )] 141 | [string] $ImagePath, 142 | 143 | [Parameter(Mandatory)] 144 | [ValidateScript({-not (Test-Path $_)})] 145 | [string] $DriveLetter, 146 | 147 | [Parameter()] 148 | [ValidateSet('Present','Absent')] 149 | [string] $Ensure = 'Present' 150 | ) 151 | 152 | Write-Verbose -Message ($localizedData.GetDiskImage -f $ImagePath) 153 | $DiskImage = Get-DiskImage -ImagePath $ImagePath 154 | if ($DiskImage.Attached) { 155 | if (($DiskImage | Get-Volume).DriveLetter -eq $DriveLetter) { 156 | Write-Verbose -Message ($localizedData.MountExistsWithDriveLetter) 157 | $MountExists = $true 158 | } else { 159 | Write-Verbose -Message ($localizedData.MountExistsWithDifferentDriveLetter) 160 | $MountExists = $false 161 | } 162 | } 163 | 164 | if ($MountExists) { 165 | if ($Ensure -eq 'Present') { 166 | Write-Verbose -Message ($localizedData.MountExistsNoAction -f $ImagePath) 167 | $true 168 | } else { 169 | Write-Verbose -Message ($localizedData.MountDoesNotExistShouldCreate -f $ImagePath) 170 | $false 171 | } 172 | } else { 173 | if ($Ensure -eq 'Absent') { 174 | Write-Verbose -Message ($localizedData.MountExistsShouldRemove -f $ImagePath) 175 | $true 176 | } else { 177 | Write-Verbose -Message ($localizedData.MountDoesNotExistNoAction -f $ImagePath) 178 | $false 179 | } 180 | } 181 | } 182 | 183 | Export-ModuleMember -Function *-TargetResource -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cDiskImage/cDiskImage.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cWindowsOS/DSCResources/cDiskImage/cDiskImage.schema.mof -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cDiskImage/en-US/cDiskImage.psd1: -------------------------------------------------------------------------------- 1 | ConvertFrom-StringData @' 2 | GetDiskImage=Getting Disk Image Instance at path {0}. 3 | DiskImageMounted=Disk image at the path {0} is mounted. 4 | DiskImageNotMounted=Disk image at the path {0} is not mounted. 5 | MountingDiskImage=Mounting disk image at path {0}. 6 | MountedDiskImage=Disk image at path {0} is mounted. 7 | SetDriveLetter=Setting Drive letter of the mounted image to {0}. 8 | DriveLetterSet=Drive letter of the mounted image set to {0}. 9 | DisMountingDiskImage=Dismounting disk image at path {0}. 10 | DismountedDiskImage=Disk image at path {0} is dismounted. 11 | MountExistsWithDriveLetter=Disk image mount exists with same drive letter as requested. 12 | MountExistsWithDifferentDriveLetter=Disk image mount exists with different drive letter than requested. 13 | MountExistsNoAction=Disk image mount for {0} already exists. No action needed. 14 | MountDoesNotExistShouldCreate=Disk image mount for {0} does not exist. It will be mounted. 15 | MountExistsShouldRemove=Disk image mount for {0} exists. It will be dismounted. 16 | MountDoesNotExistNoAction=Disk image mount for {0} does not exist. No action needed. 17 | '@ 18 | -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cLoopBackCheck/cLoopBackCheck.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cWindowsOS/DSCResources/cLoopBackCheck/cLoopBackCheck.psd1 -------------------------------------------------------------------------------- /cWindowsOS/DSCResources/cLoopBackCheck/cLoopBackCheck.schema.psm1: -------------------------------------------------------------------------------- 1 | Configuration cLoopBackCheck { 2 | Param ( 3 | [Parameter()] 4 | [ValidateSet("Present","Absent")] 5 | [String]$Ensure = "Present" 6 | ) 7 | 8 | Registry DefaultDomainName 9 | { 10 | Ensure = $Ensure 11 | Key = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa' 12 | ValueName = 'DisableLoopbackCheck' 13 | ValueData = 1 14 | ValueType = 'DWord' 15 | } 16 | } -------------------------------------------------------------------------------- /cWindowsOS/README.md: -------------------------------------------------------------------------------- 1 | # DSCResources # 2 | ### Custom DSC resource modules for managing Windows OS configuration (miscellaneous) by [PowerShell Magazine](http://www.powershellmagazine.com "PowerShell Magazine"). ### 3 | 4 | ---------- 5 | 6 | This module contains a collection of miscellaneous DSC custom and composite resources for some generic Windows OS configuration tasks. 7 | 8 | At present, this DSC resource module includes 3 resources. 9 | - [cAutoAdminLogon](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS/DSCResources/cAutoAdminLogon) is used to add or remove auto administrator logon configuration. This is a composite resource. 10 | - [cLoopBackCheck](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS/DSCResources/cLoopBackCheck) is used to enable or disable Loopback Check registry setting for web servers such as SharePoint Front End servers. This is a composite resource. 11 | - [cDiskImage](https://github.com/rchaganti/DSCResources/tree/master/cWindowsOS/DSCResources/cDiskImage) is used to mount or dismount ISO images. 12 | 13 | Before you can use any of these resources in a configuration script, you must first import the cWindowsOS module or a specific resource from this module. 14 | 15 | Import-DscResource -Module cWindowsOS 16 | Import-DscResource -Module cWindowsOS -Name cAutoAdminLogon 17 | Import-DscResource -Name cAutoAdminLogon 18 | 19 | ####Using cDiskImage resource#### 20 | The *cDiskImage* resource can be used to mount or dismount ISO images on the target systems. 21 | 22 | ![](http://i.imgur.com/p7dpa0B.png) 23 | 24 | When using this resource, both the *DriveLetter* and the *ImagePath* (ISO) must be specified. If the ISO image is already mounted with a different drive letter, this resource modifies it to the drive letter specified in the configuration script. The Id property is a unique key that is need to differentiate between resource instances where Ensure is set to Present or Absent. Without this you will not be able to mount and dismount the image in the same configuration. 25 | 26 | cDiskImage DiskImageDemo { 27 | Id = 'ImageR2-Mount' 28 | ImagePath = 'C:\Software\WS12R2.ISO' 29 | DriveLetter = 'F' 30 | Ensure = 'Present' 31 | } 32 | 33 | The value specified for *ImagePath* can be an UNC path too. At present, there is no support for providing credentials to access the UNC path. 34 | 35 | ####Using cAutoAdminLogon resource#### 36 | The *cAutoAdminLogon* is a composite resource that enables or disables auto administrator logon. 37 | 38 | ![](http://i.imgur.com/gERjAXC.png) 39 | 40 | The only mandatory parameter in this resource is the *AutoAdminCredential*. This takes a *PSCredential* object and therefore can be gathered using the *Get-Credential* cmdlet. 41 | 42 | $Credential = Get-Credential 43 | cAutoAdminLogon AutoAdminDemo { 44 | AutoAdminCredential = $Credential 45 | Ensure = 'Present' 46 | } 47 | 48 | Make a note that when using Credentials in DSC configuration scripts, you must encrypt them using certificates. If the certificates cannot be deployed in a test or development environment, you can use the *[PsDscAllowPlainTextPassword](http://www.powershellmagazine.com/2013/09/26/using-the-credential-attribute-of-dsc-file-resource/)* attribute in the DSC configuration data. Remember that this is not recommended in production environment. 49 | 50 | ####Using cLoopBackCheck resource#### 51 | The *cLoopBackCheck* resource can be used to enable or disable the *LoopBackCheck* registry setting on web servers such as SharePoint Front End servers. This is a composite resource that internally uses the *Registry* DSC resource to modify predefined settings. 52 | 53 | ![](http://i.imgur.com/gNaDzBk.png) 54 | 55 | The only property this resource requires is the *Ensure* property. By setting this to *Present*, the *LoopBackCheck* registry setting will be set and removed by setting it to *Absent*. 56 | 57 | cLoopBackCheck LoopbackDemo { 58 | Ensure = 'Present' 59 | } 60 | -------------------------------------------------------------------------------- /cWindowsOS/cWindowsOS.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/cWindowsOS/cWindowsOS.psd1 -------------------------------------------------------------------------------- /vscode/DSCResources/VSCodeExtension/VSCodeExtension.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/vscode/DSCResources/VSCodeExtension/VSCodeExtension.psm1 -------------------------------------------------------------------------------- /vscode/DSCResources/VSCodeExtension/VSCodeExtension.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/vscode/DSCResources/VSCodeExtension/VSCodeExtension.schema.mof -------------------------------------------------------------------------------- /vscode/DSCResources/VSCodeInsiderSetup/VSCodeInsiderSetup.psm1: -------------------------------------------------------------------------------- 1 | function Get-TargetResource 2 | { 3 | [CmdletBinding()] 4 | [OutputType([System.Collections.Hashtable])] 5 | param 6 | ( 7 | [parameter(Mandatory = $true)] 8 | [ValidateSet("yes")] 9 | [System.String] 10 | $IsSingleInstance, 11 | 12 | [parameter(Mandatory = $true)] 13 | [System.String] 14 | $Path 15 | ) 16 | 17 | $configuration = @{ 18 | IsSingleInstance = 'Yes' 19 | Path = $Path 20 | } 21 | 22 | Write-Verbose 'Checking if VS Code Insiders is installed ...' 23 | if (Get-VSCodeInstall) 24 | { 25 | $configuration.Add('Ensure','Present') 26 | } 27 | else 28 | { 29 | $configuration.Add('Ensure','Absent') 30 | } 31 | 32 | $configuration 33 | } 34 | 35 | 36 | function Set-TargetResource 37 | { 38 | [CmdletBinding()] 39 | param 40 | ( 41 | [parameter(Mandatory = $true)] 42 | [ValidateSet("yes")] 43 | [System.String] 44 | $IsSingleInstance, 45 | 46 | [parameter(Mandatory = $true)] 47 | [System.String] 48 | $Path, 49 | 50 | [Parameter()] 51 | [System.String] 52 | [ValidateSet('Present','Absent')] 53 | $Ensure = 'Present' 54 | ) 55 | 56 | if ($Ensure -eq 'Present') 57 | { 58 | Write-Verbose 'Installing VS Code Insiders ...' 59 | $loadInf = '@ 60 | [Setup] 61 | Lang=english 62 | Dir=C:\Program Files (x86)\Microsoft VS Code Insiders 63 | Group=Visual Studio Code 64 | NoIcons=0 65 | Tasks=desktopicon,addcontextmenufiles,addcontextmenufolders,addtopath 66 | @' 67 | 68 | $infPath = "${env:TEMP}\load.inf" 69 | $loadInf | Out-File $infPath 70 | try 71 | { 72 | Start-Process -FilePath $Path -ArgumentList "/VERYSILENT /LOADINF=${infPath}" -Wait 73 | } 74 | catch 75 | { 76 | Write-Error $_ 77 | } 78 | 79 | Write-Verbose -Message 'Testing if VS Code Insiders is installed or not ..' 80 | if (Get-VSCodeInstall) 81 | { 82 | Write-Verbose -Message 'VS Code Insiders install successful ...' 83 | } 84 | else 85 | { 86 | Write-Error -Message 'VS Code Insiders install failed ...' 87 | } 88 | } 89 | else 90 | { 91 | Write-Verbose 'Uninstalling VS Code Insiders ...' 92 | $vsCodeInstall = Get-VSCodeInstall 93 | try 94 | { 95 | Start-Process -FilePath $($vsCodeInstall.UninstallString) -ArgumentList '/VERYSILENT' -Wait 96 | Start-Sleep -Seconds 10 97 | } 98 | catch 99 | { 100 | Write-Error $_ 101 | } 102 | 103 | Write-Verbose -Message 'Testing if VS Code Insiders is uninstalled or not ..' 104 | if (Get-VSCodeInstall) 105 | { 106 | Write-Error -Message 'VS Code Insiders uninstall failed ...' 107 | } 108 | else 109 | { 110 | Write-Verbose -Message 'VS Code Insiders uninstall successful ...' 111 | } 112 | } 113 | } 114 | 115 | function Test-TargetResource 116 | { 117 | [CmdletBinding()] 118 | [OutputType([System.Boolean])] 119 | param 120 | ( 121 | [parameter(Mandatory = $true)] 122 | [ValidateSet("yes")] 123 | [System.String] 124 | $IsSingleInstance, 125 | 126 | [parameter(Mandatory = $true)] 127 | [System.String] 128 | $Path, 129 | 130 | [Parameter()] 131 | [System.String] 132 | [ValidateSet('Present','Absent')] 133 | $Ensure = 'Present' 134 | ) 135 | 136 | Write-Verbose -Message 'Testing if VS Code Insiders is installed ...' 137 | if (Get-VSCodeInstall) 138 | { 139 | if ($Ensure -eq 'Present') 140 | { 141 | Write-Verbose -Message 'VS Code Insiders is already installed. No action needed.' 142 | return $true 143 | } 144 | else 145 | { 146 | Write-Verbose -Message 'VS Code insiders is installed while it should not. It will be removed.' 147 | return $false 148 | } 149 | } 150 | else 151 | { 152 | if ($Ensure -eq 'Present') 153 | { 154 | Write-Verbose -Message 'VS Code Insiders is not installed. It will be installed.' 155 | return $false 156 | } 157 | else 158 | { 159 | Write-Verbose -Message 'VS Code Insiders is not installed. No action needed.' 160 | return $true 161 | } 162 | } 163 | } 164 | 165 | Function Get-VSCodeInstall 166 | { 167 | switch ($env:PROCESSOR_ARCHITECTURE) 168 | { 169 | 'AMD64' { $UninstallKey = 'HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*' } 170 | 'x86' { $UninstallKey = 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*' } 171 | } 172 | 173 | $products = Get-ItemProperty -Path $UninstallKey | Select DisplayName, DisplayVersion, InstallLocation, UninstallString 174 | if ($products.DisplayName -contains 'Microsoft Visual Studio Code Insiders') 175 | { 176 | return $products.Where({$_.DisplayName -eq 'Microsoft Visual Studio Code Insiders'}) 177 | } 178 | } 179 | 180 | Export-ModuleMember -Function *-TargetResource 181 | 182 | -------------------------------------------------------------------------------- /vscode/DSCResources/VSCodeSetup/VSCodeSetup.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/vscode/DSCResources/VSCodeSetup/VSCodeSetup.psm1 -------------------------------------------------------------------------------- /vscode/DSCResources/VSCodeSetup/VSCodeSetup.schema.mof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/vscode/DSCResources/VSCodeSetup/VSCodeSetup.schema.mof -------------------------------------------------------------------------------- /vscode/README.md: -------------------------------------------------------------------------------- 1 | # DSCResources # 2 | ### Custom DSC resource modules for installing Microsoft Visual Studio Code and managing extensions by [PowerShell Magazine](http://www.powershellmagazine.com "PowerShell Magazine"). ### 3 | 4 | ---------- 5 | 6 | This module contains a collection of DSC custom resources for installing VS Code and managing VS Code extensions. 7 | 8 | At present, this DSC resource module includes 2 resources. 9 | - [vscodesetup](https://github.com/rchaganti/DSCResources/tree/master/vscode/DSCResources/VSCodeSetup) is used to install VS Code editor. 10 | - [vscodeextention](https://github.com/rchaganti/DSCResources/tree/master/vscode/DSCResources/VSCodeEextension) is used to manage VS Code extensions. 11 | 12 | Before you can use any of these resources in a configuration script, you must first import the vscode module or a specific resource from this module. 13 | 14 | Import-DscResource -Module vscode 15 | Import-DscResource -Module vscode -Name vscodesetup 16 | Import-DscResource -Name vscodeextension 17 | 18 | ####Using vscodesetup resource#### 19 | The *vscodesetup* resource can be used to install Microsoft Visual Studio Code editor. 20 | 21 | ![](http://i.imgur.com/rndNDqC.png) 22 | 23 | When using this resource, both the *IsSingleInstance* and the *Path* must be specified. The *IsSingleInstance* can only have 'Yes' as a possible valid value. This is done to ensure that this resource gets used only once in the configuration document. The *Path* property takes the path to VS Code setup file. This can be downloaded from [https://go.microsoft.com/fwlink/?LinkID=623230](https://go.microsoft.com/fwlink/?LinkID=623230). 24 | 25 | VSCodeSetup VSCodeSetup { 26 | IsSingleInstance = 'yes' 27 | Path = 'C:\temp\vscodesetup.exe' 28 | PsDscRunAsCredential = $Credential 29 | Ensure = 'Present' 30 | } 31 | 32 | The *PsDscRunAsCredential* is important because VS Code install creates the .vscode folder that stores all extensions under the logged-in user's homepath. Without this, this folder gets created at the root of system drive. So, using *PsDscRunAsCredential*, you need to pass the current user credentials. 33 | 34 | ####Using vscodeextension resource#### 35 | The *vscodeextension* can be used to install new VS Code extensions from the market place. At this point in time, this relies on the commandline provided by VS Code but I am exploring other alternatives. Therefore, only VS Code version 1.2.0 onwards is supported for installing VS Code extensions using this resource. 36 | 37 | ![](http://i.imgur.com/pRREXL5.png) 38 | 39 | The only mandatory property in this resource is the *Name* property. You can use this to provide the name of the VS Code extension. Instead of dividing this into two properties like Publisher and Name, I decided to merge both of them into the *Name* property. Therefore the value to this property must be of the form *Publisher.ExtensionName*. You can find this from the marketplace URL for the extension. Using this method, you can be sure that you are always installing the right extension. 40 | 41 | vscodeextension PowerShellExtension { 42 | Name = 'ms-vscode.PowerShell' 43 | PsDscRunAsCredential = $Credential 44 | Ensure = 'Present' 45 | DependsOn = '[vscodesetup]VSCodeSetup' 46 | } 47 | 48 | Like the *vscodesetup* resource configuration, this resource requires *PsDscRunAsCredential* to ensure the extension gets installed for the current user. Make a note that when using Credentials in DSC configuration scripts, you must encrypt them using certificates. If the certificates cannot be deployed in a test or development environment, you can use the *[PsDscAllowPlainTextPassword](http://www.powershellmagazine.com/2013/09/26/using-the-credential-attribute-of-dsc-file-resource/)* attribute in the DSC configuration data. Remember that this is not recommended in production environment. 49 | 50 | Here is an example configuration document that installs VS Code and a couple of extensions. 51 | 52 | $ConfigurationData = @{ 53 | AllNodes = 54 | @( 55 | @{ 56 | NodeName = '*' 57 | PSDscAllowPlainTextPassword = $true 58 | }, 59 | @{ 60 | NodeName = 'localhost' 61 | } 62 | ) 63 | } 64 | 65 | Configuration VSCodeConfig { 66 | param ( 67 | [pscredential] $Credential 68 | ) 69 | Import-DscResource -ModuleName VSCode 70 | 71 | Node $AllNodes.NodeName { 72 | VSCodeSetup VSCodeSetup { 73 | IsSingleInstance = 'yes' 74 | Path = 'C:\temp\vscodesetup.exe' 75 | PsDscRunAsCredential = $Credential 76 | Ensure = 'Present' 77 | } 78 | 79 | vscodeextension PowerShellExtension { 80 | Name = 'ms-vscode.PowerShell' 81 | PsDscRunAsCredential = $Credential 82 | Ensure = 'Present' 83 | DependsOn = '[vscodesetup]VSCodeSetup' 84 | } 85 | 86 | vscodeextension CPPExtension { 87 | Name = 'ms-vscode.cpptools' 88 | PsDscRunAsCredential = $Credential 89 | Ensure = 'Present' 90 | DependsOn = '[vscodesetup]VSCodeSetup' 91 | } 92 | } 93 | } 94 | 95 | VSCodeConfig -ConfigurationData $ConfigurationData -Credential (Get-Credential) 96 | 97 | ## TODO ## 98 | There are certainly a few things I want to improve in this and also add more resources for customizing VS Code environment. I also want to explore if there is a better way to install extensions instead of using the commandline provided with version 1.2.0. -------------------------------------------------------------------------------- /vscode/vscode.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/DSCResources/6389738a52ba88fd9bc611393daecea9c2f4dea8/vscode/vscode.psd1 --------------------------------------------------------------------------------