├── README.md ├── LICENSE ├── SECURITY.md ├── .gitignore └── PSDesiredStateConfiguration.Reverse.ps1 /README.md: -------------------------------------------------------------------------------- 1 | # PSDesiredStateConfiguration.Reverse 2 | ReverseDSC Orchestrator for the core PSDesiredStateConfiguration Module 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /PSDesiredStateConfiguration.Reverse.ps1: -------------------------------------------------------------------------------- 1 | <#PSScriptInfo 2 | 3 | .VERSION 1.0.0.2 4 | 5 | .GUID 7269a91a-eab7-43c7-ae64-1722ff9a15cd 6 | 7 | .AUTHOR Microsoft Corporation 8 | 9 | .COMPANYNAME Microsoft Corporation 10 | 11 | .EXTERNALMODULEDEPENDENCIES 12 | 13 | .TAGS Windows,ReverseDSC,PSDesiredStateConfiguration 14 | 15 | .RELEASENOTES 16 | 17 | * Added support for Files and Folders; 18 | #> 19 | 20 | #Requires -Modules @{ModuleName="ReverseDSC";ModuleVersion="1.7.3.0"} 21 | 22 | <# 23 | 24 | .DESCRIPTION 25 | Extracts the DSC Configuration of an existing environment, allowing you to analyze it or to replicate it. 26 | 27 | #> 28 | 29 | param( 30 | [System.String[]] $RegistryPaths, 31 | [Hashtable[]] $Folders 32 | ) 33 | 34 | <## Script Settings #> 35 | $VerbosePreference = "SilentlyContinue" 36 | 37 | <## Scripts Variables #> 38 | $Script:allEntries = @() 39 | $Script:dscConfigContent = "" 40 | $Script:DSCPath = "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\" 41 | $Script:configName = "CoreEnvironment" 42 | 43 | <# Retrieves Information about the current script from the PSScriptInfo section above #> 44 | try { 45 | $currentScript = Test-ScriptFileInfo $SCRIPT:MyInvocation.MyCommand.Path 46 | $Script:version = $currentScript.Version.ToString() 47 | } 48 | catch { 49 | $Script:version = "N/A" 50 | } 51 | 52 | <## This is the main function for this script. It acts as a call dispatcher, calling the various functions required in the proper order to 53 | get the full picture of the environment; #> 54 | function Orchestrator 55 | { 56 | <# Import the ReverseDSC Core Engine #> 57 | $ReverseDSCModule = "ReverseDSC.Core.psm1" 58 | $module = (Join-Path -Path $PSScriptRoot -ChildPath $ReverseDSCModule -Resolve -ErrorAction SilentlyContinue) 59 | if($module -eq $null) 60 | { 61 | $module = "ReverseDSC" 62 | } 63 | Import-Module -Name $module -Force 64 | 65 | 66 | $Script:dscConfigContent += "<# Generated with SQLServer.Reverse " + $script:version + " #>`r`n" 67 | $Script:dscConfigContent += "Configuration $Script:configName`r`n" 68 | $Script:dscConfigContent += "{`r`n" 69 | 70 | Write-Host "Configuring Dependencies..." -BackgroundColor DarkGreen -ForegroundColor White 71 | Set-Imports 72 | 73 | $Script:dscConfigContent += " Node $env:COMPUTERNAME`r`n" 74 | $Script:dscConfigContent += " {`r`n" 75 | 76 | if($null -ne $RegistryPaths) 77 | { 78 | Write-Host "Scanning [Registry]..." -BackgroundColor DarkGreen -ForegroundColor White 79 | Read-Registry -Paths $RegistryPaths 80 | } 81 | 82 | if($null -ne $Folders) 83 | { 84 | Write-Host "Scanning [Files and Folders]..." -BackgroundColor DarkGreen -ForegroundColor White 85 | Read-FilesAndFolders -Paths $Folders 86 | } 87 | 88 | Write-Host "Configuring Local Configuration Manager (LCM)..." -BackgroundColor DarkGreen -ForegroundColor White 89 | Set-LCM 90 | 91 | $Script:dscConfigContent += "`r`n }`r`n" 92 | $Script:dscConfigContent += "}`r`n" 93 | 94 | Write-Host "Setting Configuration Data..." -BackgroundColor DarkGreen -ForegroundColor White 95 | Set-ConfigurationData 96 | 97 | $Script:dscConfigContent += "$Script:configName -ConfigurationData `$ConfigData" 98 | } 99 | 100 | #region Reverse Functions 101 | function Read-Registry($Paths) 102 | { 103 | $module = Resolve-Path ($Script:DSCPath + "\DSCResources\MSFT_RegistryResource\MSFT_RegistryResource.psm1") 104 | Import-Module $module 105 | $params = Get-DSCFakeParameters -ModulePath $module 106 | 107 | foreach($path in $Paths) 108 | { 109 | SetupProvider -KeyName ([ref]$path) 110 | $keys = Get-Item $path 111 | foreach($key in $keys) 112 | { 113 | <# Setting Primary Keys #> 114 | $params.Key = $key.Name 115 | 116 | foreach($prop in $key.Property) 117 | { 118 | $params.ValueName = $prop 119 | $results = Get-TargetResource @params 120 | 121 | if($results.Ensure -ne "Absent") 122 | { 123 | $fullEntryName = $key.Name + "\" + $prop 124 | if(!$Script:allEntries.Contains($fullEntryName)) 125 | { 126 | $Script:allEntries += $fullEntryName 127 | Write-Host "$key.Name\$prop" 128 | $Script:dscConfigContent += " Registry " + [System.Guid]::NewGuid().toString() + "`r`n" 129 | $Script:dscConfigContent += " {`r`n" 130 | $Script:dscConfigContent += Get-DSCBlock -Params $results -ModulePath $module 131 | $Script:dscConfigContent += " }`r`n" 132 | } 133 | } 134 | } 135 | } 136 | 137 | $subKeys = Get-ChildItem $Path 138 | foreach($subkey in $subKeys) 139 | { 140 | Read-Registry -Path $subkey.Name 141 | } 142 | } 143 | } 144 | 145 | function Read-FilesAndFolders($Paths) 146 | { 147 | foreach($path in $Paths) 148 | { 149 | $root = Get-Item $path.Source # For Verification 150 | if($null -ne $root) 151 | { 152 | $files = Get-ChildItem -Path $path.Source -Recurse 153 | 154 | foreach($file in $files) 155 | { 156 | Read-SubFilesAndFolders $file -Source $path.Source -Shared $path.SharedSource 157 | } 158 | } 159 | } 160 | } 161 | 162 | function Read-SubFilesAndFolders($file, $Source, $Shared) 163 | { 164 | Write-Host $file.FullName 165 | $root = Get-Item $file.FullName # For Verification 166 | $Script:dscConfigContent += " File " + [System.Guid]::NewGuid().toString() + "`r`n" 167 | $Script:dscConfigContent += " {`r`n" 168 | $Script:dscConfigContent += " DestinationPath = '" + $file.FullName + "';`r`n" 169 | if($root.PSIsContainer) 170 | { 171 | $Script:dscConfigContent += " Type = 'Directory';`r`n" 172 | $Script:dscConfigContent += " Recurse = `$True;`r`n" 173 | } 174 | else 175 | { 176 | $Script:dscConfigContent += " Type = 'File';`r`n" 177 | } 178 | 179 | # Do a check to see if we need to replace the source path with a SharedSource instead; 180 | if($null -ne $Shared) 181 | { 182 | $Source = $file.FullName.Replace($Source, $Shared) 183 | } 184 | 185 | $Script:dscConfigContent += " SourcePath = '" + $Source + "';`r`n" 186 | $Script:dscConfigContent += " Ensure = 'Present';`r`n" 187 | $Script:dscConfigContent += " }`r`n" 188 | } 189 | #endregion 190 | 191 | # Sets the DSC Configuration Data for the current server; 192 | function Set-ConfigurationData 193 | { 194 | $Script:dscConfigContent += "`$ConfigData = @{`r`n" 195 | $Script:dscConfigContent += " AllNodes = @(`r`n" 196 | 197 | $tempConfigDataContent += " @{`r`n" 198 | $tempConfigDataContent += " NodeName = `"$env:COMPUTERNAME`";`r`n" 199 | $tempConfigDataContent += " PSDscAllowPlainTextPassword = `$true;`r`n" 200 | $tempConfigDataContent += " PSDscAllowDomainUser = `$true;`r`n" 201 | $tempConfigDataContent += " }`r`n" 202 | 203 | $Script:dscConfigContent += $tempConfigDataContent 204 | $Script:dscConfigContent += ")}`r`n" 205 | } 206 | 207 | <## This function ensures all required DSC Modules are properly loaded into the current PowerShell session. #> 208 | function Set-Imports 209 | { 210 | $Script:dscConfigContent += " Import-DscResource -ModuleName PSDesiredStateConfiguration`r`n" 211 | } 212 | 213 | <## This function sets the settings for the Local Configuration Manager (LCM) component on the server we will be configuring using our resulting DSC Configuration script. The LCM component is the one responsible for orchestrating all DSC configuration related activities and processes on a server. This method specifies settings telling the LCM to not hesitate rebooting the server we are configurating automatically if it requires a reboot (i.e. During the SharePoint Prerequisites installation). Setting this value helps reduce the amount of manual interaction that is required to automate the configuration of our SharePoint farm using our resulting DSC Configuration script. #> 214 | function Set-LCM 215 | { 216 | $Script:dscConfigContent += " LocalConfigurationManager" + "`r`n" 217 | $Script:dscConfigContent += " {`r`n" 218 | $Script:dscConfigContent += " RebootNodeIfNeeded = `$True`r`n" 219 | $Script:dscConfigContent += " }`r`n" 220 | } 221 | 222 | 223 | <# This function is responsible for saving the output file onto disk. #> 224 | function Get-ReverseDSC() 225 | { 226 | <## Call into our main function that is responsible for extracting all the information about our environment; #> 227 | Orchestrator 228 | 229 | <## Prompts the user to specify the FOLDER path where the resulting PowerShell DSC Configuration Script will be saved. #> 230 | $fileName = "PSDesiredStateConfiguration.DSC.ps1" 231 | $OutputDSCPath = Read-Host "Please enter the full path of the output folder for DSC Configuration (will be created as necessary)" 232 | 233 | <## Ensures the specified output folder path actually exists; if not, tries to create it and throws an exception if we can't. ##> 234 | while (!(Test-Path -Path $OutputDSCPath -PathType Container -ErrorAction SilentlyContinue)) 235 | { 236 | try 237 | { 238 | Write-Output "Directory `"$OutputDSCPath`" doesn't exist; creating..." 239 | New-Item -Path $OutputDSCPath -ItemType Directory | Out-Null 240 | if ($?) {break} 241 | } 242 | catch 243 | { 244 | Write-Warning "$($_.Exception.Message)" 245 | Write-Warning "Could not create folder $OutputDSCPath!" 246 | } 247 | $OutputDSCPath = Read-Host "Please Enter Output Folder for DSC Configuration (Will be Created as Necessary)" 248 | } 249 | <## Ensures the path we specify ends with a Slash, in order to make sure the resulting file path is properly structured. #> 250 | if(!$OutputDSCPath.EndsWith("\") -and !$OutputDSCPath.EndsWith("/")) 251 | { 252 | $OutputDSCPath += "\" 253 | } 254 | 255 | <## Save the content of the resulting DSC Configuration file into a file at the specified path. #> 256 | $outputDSCFile = $OutputDSCPath + $fileName 257 | $Script:dscConfigContent | Out-File $outputDSCFile 258 | Write-Output "Done." 259 | <## Wait a couple of seconds, then open our $outputDSCPath in Windows Explorer so we can review the glorious output. ##> 260 | Start-Sleep 2 261 | Invoke-Item -Path $OutputDSCPath 262 | } 263 | 264 | FUNCTION SetupProvider 265 | { 266 | param 267 | ( 268 | [ValidateNotNull()] 269 | [ref] $KeyName 270 | ) 271 | 272 | # Fix $KeyName if required 273 | if (!$KeyName.Value.ToString().Contains(":")) 274 | { 275 | if ($KeyName.Value.ToString().StartsWith("hkey_users","OrdinalIgnoreCase")) 276 | { 277 | $KeyName.Value = $KeyName.Value.ToString() -replace "hkey_users", "HKUS:" 278 | } 279 | elseif ($KeyName.Value.ToString().StartsWith("hkey_current_config","OrdinalIgnoreCase")) 280 | { 281 | $KeyName.Value = $KeyName.Value.ToString() -replace "hkey_current_config", "HKCC:" 282 | } 283 | elseif ($KeyName.Value.ToString().StartsWith("hkey_classes_root","OrdinalIgnoreCase")) 284 | { 285 | $KeyName.Value = $KeyName.Value.ToString() -replace "hkey_classes_root", "HKCR:" 286 | } 287 | elseif ($KeyName.Value.ToString().StartsWith("hkey_local_machine","OrdinalIgnoreCase")) 288 | { 289 | $KeyName.Value = $KeyName.Value.ToString() -replace "hkey_local_machine", "HKLM:" 290 | } 291 | elseif ($KeyName.Value.ToString().StartsWith("hkey_current_user","OrdinalIgnoreCase")) 292 | { 293 | $KeyName.Value = $KeyName.Value.ToString() -replace "hkey_current_user", "HKCU:" 294 | } 295 | else 296 | { 297 | $errorMessage = $localizedData.InvalidRegistryHiveSpecified -f $Key 298 | ThrowError -ExceptionName "System.ArgumentException" -ExceptionMessage $errorMessage -ExceptionObject $KeyName -ErrorId "InvalidRegistryHive" -ErrorCategory InvalidArgument 299 | } 300 | } 301 | } 302 | 303 | Get-ReverseDSC 304 | --------------------------------------------------------------------------------