6464
6565 Note: Using Write-Host is generally - but not always - bad practice
6666 Note: Verbose output during module import is generally discouraged (doesn't apply to tests of course)
67-
68- . NOTES
69- Version 1.1.0.0
70- Author: Friedrich Weinmann
71- Created on: August 7th, 2016
7267 #>
73- [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSUseShouldProcessForStateChangingFunctions" , " " )]
7468 [CmdletBinding (DefaultParameterSetName = " Name" , SupportsShouldProcess = $true )]
7569 Param (
76- [Parameter (Mandatory = $true , Position = 0 , ParameterSetName = " Name" )]
70+ [Parameter (Mandatory = $true , Position = 0 , ParameterSetName = " Name" , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
7771 [Alias (' n' )]
7872 [string ]
7973 $Name ,
113107 $NoneAutoImport
114108 )
115109
116- # region AllAutoImport
117- if ($AllAutoImport )
110+ process
118111 {
119- $allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
120- if ($PSCmdlet .ShouldProcess (( $allModules .Name -join " , " ) , " Configuring modules to automatically import " ) )
112+ # region AllAutoImport
113+ if ($AllAutoImport )
121114 {
122- foreach ($module in $allModules )
115+ $allModules = Import-Clixml (Get-PSFConfigValue - FullName ' PSModuleDevelopment.Debug.ConfigPath' )
116+ if (Test-PSFShouldProcess - Target ($allModules.Name -join " , " ) - Action " Configuring modules to automatically import" - PSCmdlet $PSCmdlet )
123117 {
124- $module.AutoImport = $true
118+ foreach ($module in $allModules )
119+ {
120+ $module.AutoImport = $true
121+ }
122+ Export-Clixml - InputObject $allModules - Path (Get-PSFConfigValue - FullName ' PSModuleDevelopment.Debug.ConfigPath' )
125123 }
126- Export-Clixml - InputObject $allModules - Path $PSModuleDevelopment_ModuleConfigPath
124+ return
127125 }
128- }
129- # endregion AllAutoImport
130-
131- # region NoneAutoImport
132- if ($NoneAutoImport )
133- {
134- $allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
135- if ($PSCmdlet.ShouldProcess (($allModules.Name -join " , " ), " Configuring modules to not automatically import" ))
126+ # endregion AllAutoImport
127+
128+ # region NoneAutoImport
129+ if ($NoneAutoImport )
136130 {
137- foreach ($module in $allModules )
131+ $allModules = Import-Clixml - Path (Get-PSFConfigValue - FullName ' PSModuleDevelopment.Debug.ConfigPath' )
132+ if (Test-PSFShouldProcess - Target ($allModules.Name -join " , " ) - Action " Configuring modules to not automatically import" - PSCmdlet $PSCmdlet )
138133 {
139- $module.AutoImport = $false
134+ foreach ($module in $allModules )
135+ {
136+ $module.AutoImport = $false
137+ }
138+ Export-Clixml - InputObject $allModules - Path (Get-PSFConfigValue - FullName ' PSModuleDevelopment.Debug.ConfigPath' )
140139 }
141- Export-Clixml - InputObject $allModules - Path $PSModuleDevelopment_ModuleConfigPath
140+ return
142141 }
143- }
144- # endregion NoneAutoImport
145-
146- # region Name
147- # Import all module-configurations
148- $allModules = Import-Clixml $PSModuleDevelopment_ModuleConfigPath
149-
150- # If a configuration already exists, change only those values that were specified
151- if ($module = $allModules | Where-Object { $_.Name -eq $Name })
152- {
153- if (Test-PSFParameterBinding - ParameterName " AutoImport" ) { $module.AutoImport = $AutoImport.ToBool () }
154- if (Test-PSFParameterBinding - ParameterName " DebugMode" ) { $module.DebugMode = $DebugMode.ToBool () }
155- if (Test-PSFParameterBinding - ParameterName " PreImportAction" ) { $module.PreImportAction = $PreImportAction }
156- if (Test-PSFParameterBinding - ParameterName " PostImportAction" ) { $module.PostImportAction = $PostImportAction }
157- if (Test-PSFParameterBinding - ParameterName " Priority" ) { $module.Priority = $Priority }
158- }
159- # If no configuration exists yet, create a new one with all parameters as specified
160- else
161- {
162- $module = New-Object PSObject - Property @ {
163- Name = $Name
164- AutoImport = $AutoImport.ToBool ()
165- DebugMode = $DebugMode.ToBool ()
166- PreImportAction = $PreImportAction
167- PostImportAction = $PostImportAction
168- Priority = $Priority
142+ # endregion NoneAutoImport
143+
144+ # region Name
145+ # Import all module-configurations
146+ $allModules = Import-Clixml - Path (Get-PSFConfigValue - FullName ' PSModuleDevelopment.Debug.ConfigPath' )
147+
148+ # If a configuration already exists, change only those values that were specified
149+ if ($module = $allModules | Where-Object Name -eq $Name )
150+ {
151+ if (Test-PSFParameterBinding - ParameterName " AutoImport" ) { $module.AutoImport = $AutoImport.ToBool () }
152+ if (Test-PSFParameterBinding - ParameterName " DebugMode" ) { $module.DebugMode = $DebugMode.ToBool () }
153+ if (Test-PSFParameterBinding - ParameterName " PreImportAction" ) { $module.PreImportAction = $PreImportAction }
154+ if (Test-PSFParameterBinding - ParameterName " PostImportAction" ) { $module.PostImportAction = $PostImportAction }
155+ if (Test-PSFParameterBinding - ParameterName " Priority" ) { $module.Priority = $Priority }
169156 }
170- }
171-
172- # Add new module configuration to all (if any) other previous configurations and export it to config file
173- $newModules = @ (($allModules | Where-Object { $_.Name -ne $Name }), $module )
174- if ($PSCmdlet.ShouldProcess ($name , " Changing debug settings for module" ))
175- {
176- Export-Clixml - InputObject $newModules - Path $PSModuleDevelopment_ModuleConfigPath
177- }
178- # endregion Name
157+ # If no configuration exists yet, create a new one with all parameters as specified
158+ else
159+ {
160+ $module = [pscustomobject ]@ {
161+ Name = $Name
162+ AutoImport = $AutoImport.ToBool ()
163+ DebugMode = $DebugMode.ToBool ()
164+ PreImportAction = $PreImportAction
165+ PostImportAction = $PostImportAction
166+ Priority = $Priority
167+ }
168+ }
169+
170+ # Add new module configuration to all (if any) other previous configurations and export it to config file
171+ $newModules = @ (($allModules | Where-Object Name -ne $Name ), $module )
172+
173+ if (Test-PSFShouldProcess - Target $name - Action " Changing debug settings for module" - PSCmdlet $PSCmdlet )
174+ {
175+ Export-Clixml - InputObject $newModules - Path (Get-PSFConfigValue - FullName ' PSModuleDevelopment.Debug.ConfigPath' )
176+ }
177+ # endregion Name
178+ }
179179}
180180Set-Alias - Name smd - Value Set-PSMDModuleDebug - Option AllScope - Scope Global
0 commit comments