@@ -30,73 +30,6 @@ function Get-ChefPackage {
3030 Get-WmiObject - Class Win32_Product | Where-Object { $_.Name.contains (" Chef Client" ) }
3131}
3232
33- function Get-PublicSettings-From-Config-Json ($key , $powershellVersion ) {
34- Try
35- {
36- $azure_config_file = Get-Azure - Config- Path($powershellVersion )
37- $json_contents = Get-Content $azure_config_file
38- $normalized_json = normalize_json($json_contents )
39-
40- if ( $powershellVersion -ge 3 ) {
41- $value = ($normalized_json | ConvertFrom-Json | Select - expand runtimeSettings | Select - expand handlerSettings | Select - expand publicSettings).$key
42- }
43- else {
44- $ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
45- $value = $ser.DeserializeObject ($normalized_json ).runtimeSettings[0 ].handlerSettings.publicSettings.$key
46- }
47- $value
48- }
49- Catch
50- {
51- $ErrorMessage = $_.Exception.Message
52- $FailedItem = $_.Exception.ItemName
53- echo " Failed to read file: $FailedItem . The error message was $ErrorMessage "
54- throw " Error in Get-PublicSettings-From-Config-Json. Couldn't parse $azure_config_file "
55- }
56- }
57-
58- function normalize_json ($json ) {
59- $json -Join " "
60- }
61-
62- function Get-Azure-Config-Path ($powershellVersion ) {
63- $chefExtensionRoot = Chef- GetExtensionRoot
64-
65- Try
66- {
67- # Reading chef_extension_root/HandlerEnvironment.json file
68- $handler_file = " $chefExtensionRoot \\HandlerEnvironment.json"
69-
70- if ( $powershellVersion -ge 3 ) {
71- $config_folder = (((Get-Content $handler_file ) | ConvertFrom-Json )[0 ] | Select - expand handlerEnvironment).configFolder
72- }
73- else {
74- add-type - assembly system.web.extensions
75- $ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
76- $config_folder = ($ser.DeserializeObject ($ (Get-Content $handler_file )))[0 ].handlerEnvironment.configFolder
77- }
78-
79- # Get the last .settings file
80- $config_files = get-childitem $config_folder - recurse | where {$_.extension -eq " .settings" }
81-
82- if ($config_files -is [system.array ]) {
83- $config_file_name = $config_files [-1 ].Name
84- }
85- else {
86- $config_file_name = $config_files.Name
87- }
88-
89- " $config_folder \$config_file_name "
90- }
91- Catch
92- {
93- $ErrorMessage = $_.Exception.Message
94- $FailedItem = $_.Exception.ItemName
95- echo " Failed to read file: $FailedItem . The error message was $ErrorMessage "
96- throw " Error in Get-Azure-Config-Path. Couldn't parse the HandlerEnvironment.json file"
97- }
98- }
99-
10033function Install-ChefClient {
10134 # Source the shared PS
10235 . $ (Get-SharedHelper )
@@ -155,19 +88,4 @@ function Get-SharedHelper {
15588 " $chefExtensionRoot \\bin\\shared.ps1"
15689}
15790
158- # This method is called separetely from enable.cmd before calling Install-ChefClient
159- # Sourcing the script again refreshes the powershell console and the changes
160- # of registry key become available
161- function Run-Powershell2-With-Dot-Net4 {
162- # Source the shared PS
163- . $ (Get-SharedHelper )
164- $powershellVersion = Get-PowershellVersion
165-
166- if ( $powershellVersion -lt 3 ) {
167- reg add hklm\software\microsoft\.netframework / v OnlyUseLatestCLR / t REG_DWORD / d 1 / f
168- reg add hklm\software\wow6432node\microsoft\.netframework / v OnlyUseLatestCLR / t REG_DWORD / d 1 / f
169- }
170- }
171-
17291Export-ModuleMember - Function Install-ChefClient
173- Export-ModuleMember - Function Run- Powershell2- With- Dot- Net4
0 commit comments