From 31d526b4a5f826ccb348fad59c288139204bb0f6 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Tue, 24 Oct 2017 17:27:09 -0700 Subject: [PATCH 1/9] initial changes --- .../AzureRM.Resources.psm1 | 45 +++++++++++++++++++ .../Commands.ResourceManager.Common.csproj | 3 ++ .../Resources/AzureRM.Resources.psd1 | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 diff --git a/src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 b/src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 new file mode 100644 index 000000000000..1beadd70442b --- /dev/null +++ b/src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 @@ -0,0 +1,45 @@ +Function Init() +{ + #Initialize Code +} + +$dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Commands.ResourceManager.Cmdlets.dll' +$Assembly = [Reflection.Assembly]::LoadFrom($dllPath) +$AllCmdlets = $Assembly.GetTypes() | where {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} + +$dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Commands.Resources.dll' +$Assembly = [Reflection.Assembly]::LoadFrom($dllPath) +$AllCmdlets += $Assembly.GetTypes() | where {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} + +$FilteredCommands = @() +$AllCmdlets | ForEach-Object { + $rgParameter = $_.GetProperties() | Where-Object {$_.Name -eq "ResourceGroupName"} + if ($rgParameter -ne $null) { + $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} + $isMandatory = $true + $parameterSets | ForEach-Object { + $hasParameterSet = $_.NamedArguments | where {$_.MemberName -eq "ParameterSetName"} + $MandatoryParam = $_.NamedArguments | where {$_.MemberName -eq "Mandatory"} + if (($hasParameterSet -ne $null) -or (!$MandatoryParam.TypedValue.Value)) { + $isMandatory = $false + } + } + if ($isMandatory) { + $FilteredCommands += $_ + } + } +} + +$FilteredCommands | ForEach-Object { + $input = $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").VerbName + "-" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").NounName + ":ResourceGroupName" + $global:PSDefaultParameterValues.Add($input, + { + $context = Get-AzureRmContext + if ($context.ExtendedProperties.ContainsKey("Default Resource Group")) { + $context.ExtendedProperties["Default Resource Group"] + } + }) +} + +#Execute Init +#Init \ No newline at end of file diff --git a/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj b/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj index 2df18752054b..a5eccbcd503f 100644 --- a/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj +++ b/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj @@ -201,6 +201,9 @@ + + Always + Designer diff --git a/src/ResourceManager/Resources/AzureRM.Resources.psd1 b/src/ResourceManager/Resources/AzureRM.Resources.psd1 index a78f59ac1129..833f19fd980e 100644 --- a/src/ResourceManager/Resources/AzureRM.Resources.psd1 +++ b/src/ResourceManager/Resources/AzureRM.Resources.psd1 @@ -9,7 +9,7 @@ @{ # Script module or binary module file associated with this manifest. -# RootModule = '' +RootModule = 'AzureRM.Resources.psm1' # Version number of this module. ModuleVersion = '4.4.1' From 07c1e06138aad1b7bd7ff60a8213a021a0672c48 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Wed, 25 Oct 2017 16:58:36 -0700 Subject: [PATCH 2/9] put script in startup file --- .../Commands.ResourceManager.Common.csproj | 3 --- .../Commands.Resources/Commands.Resources.csproj | 14 +++++++------- .../StartupScripts/DefaultResourceGroup.psm1} | 11 ++--------- 3 files changed, 9 insertions(+), 19 deletions(-) rename src/ResourceManager/{Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 => Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1} (91%) diff --git a/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj b/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj index a5eccbcd503f..2df18752054b 100644 --- a/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj +++ b/src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj @@ -201,9 +201,6 @@ - - Always - Designer diff --git a/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj b/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj index ae5afc12a130..eefd5c8393fe 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj +++ b/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj @@ -173,6 +173,9 @@ + + Always + @@ -188,13 +191,10 @@ - - - - + + + + \ No newline at end of file diff --git a/src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 b/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 similarity index 91% rename from src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 rename to src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 index 1beadd70442b..c658808891b3 100644 --- a/src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRM.Resources.psm1 +++ b/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 @@ -1,9 +1,5 @@ -Function Init() -{ - #Initialize Code -} - -$dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Commands.ResourceManager.Cmdlets.dll' +# Set Default Resource Group for Resources cmdlets +$dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Management.ResourceManager.dll' $Assembly = [Reflection.Assembly]::LoadFrom($dllPath) $AllCmdlets = $Assembly.GetTypes() | where {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} @@ -40,6 +36,3 @@ $FilteredCommands | ForEach-Object { } }) } - -#Execute Init -#Init \ No newline at end of file From ccb1a303a627cd02db01b7289e0009c8b557d312 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Thu, 26 Oct 2017 17:15:05 -0700 Subject: [PATCH 3/9] remove old changes --- src/ResourceManager/Resources/AzureRM.Resources.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResourceManager/Resources/AzureRM.Resources.psd1 b/src/ResourceManager/Resources/AzureRM.Resources.psd1 index 833f19fd980e..a78f59ac1129 100644 --- a/src/ResourceManager/Resources/AzureRM.Resources.psd1 +++ b/src/ResourceManager/Resources/AzureRM.Resources.psd1 @@ -9,7 +9,7 @@ @{ # Script module or binary module file associated with this manifest. -RootModule = 'AzureRM.Resources.psm1' +# RootModule = '' # Version number of this module. ModuleVersion = '4.4.1' From 29371d5d4275921dd8ff65b4ad1d13d5cfafe9a7 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Tue, 31 Oct 2017 18:00:59 -0700 Subject: [PATCH 4/9] Move script to updatemodule --- .../StartupScripts/DefaultResourceGroup.psm1 | 1 + tools/AzureRM.Example.psm1 | Bin 740 -> 3764 bytes tools/UpdateModules.ps1 | 11 ++++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 b/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 index c658808891b3..11dcb8969ca2 100644 --- a/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 +++ b/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 @@ -1,4 +1,5 @@ # Set Default Resource Group for Resources cmdlets +$nestedModules = Test-ModuleManifest '../AzureRM.Profile.psd1' $dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Management.ResourceManager.dll' $Assembly = [Reflection.Assembly]::LoadFrom($dllPath) $AllCmdlets = $Assembly.GetTypes() | where {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} diff --git a/tools/AzureRM.Example.psm1 b/tools/AzureRM.Example.psm1 index d71d57baa058d90cfccde11d897061b8e6e40af9..56bb44630a03edf0dd6ae29f28c8f0bc7870c362 100644 GIT binary patch literal 3764 zcmd5FGuf99av}#(m4?)@bAbJANPGQ$bp)L;-ecHE@Et*_BQvSt`xG|2crt?35p2@( zJGFeTpFGjWD#pIo=vPI$DNWrKcv+X0`sSjxll)bdb7?}N2dizxA;C^ty&Phfo{r@s zb_RG#R6=-0v?#M9yNYB}C9BYsV3)BZb7YBX73ZmCvWVdXr>U73(+lUhOdJ4K+Knx!fgiCZFjmwOi$csDiBY73!mg`W?Zi2>!ADhKOj{x^diFB?`rOlyf#h zVQnTrd8S;RC}M#Skxz(>Ozjn*!B|;oWO|~0)$wiB)xoY+4`W*1b(TWpw~ctL0=v)= zL$(bxV(1K{l*wpbPif9VA9oQC=s|>+M=i?}!_N3@Y&wJo1NEPgNAQBETj!0`vt?!# z*);?=;nWuLIYv$9yP9W}%hI`WfIVjn53Sp<$8DOgG~(<^M44P7waRnF$Ei( zv_pCe7TKqWTGyq)DCD_R%t?n( zJ~Md@9wWxc9?qW2$s1fFK zsySg5G8eS_u;>8Hq1F5;JZC>62b~5^mDOmOWha|PivH$t@_7GyZ}Zl({yD~z^Xrf; z=6+SP&#HN`Cfab(g`?DsCQPk&m#WD!{y5usZ}M~6SYrK-Yrk@lu3~Stj+wdjopMhn zxtoh=duI1(eRuOpU<@%j4d+mrLpJNyO|2bt#U|>NlZ{-r`%?@Yd2?dlVvTUJP(P;w zYuruo^n5Am6T3KR_p?r_e)iyJ2~||WH`i8c|BJs3oey!&-`YmggL9R9xd9JH=p5u@ z4IS#K_j*6ceRf~zjf>3kGlsU@eWEAdkQ?KGp;<-Vz9Vy-?ia`%=R5OhlIAP*`FhCe z3UME$PIvE*5D9N)*{RHFmA%ot$B7xbKxygUOpwDcNX_69Dt@{0^6_ov)8&(GUoFsO Nr?7uzR>kRi(_gKVTE+kX delta 7 OcmdlY`-FAF6D9x-0|QY2 diff --git a/tools/UpdateModules.ps1 b/tools/UpdateModules.ps1 index 22959c4dbb10..b6965414667f 100644 --- a/tools/UpdateModules.ps1 +++ b/tools/UpdateModules.ps1 @@ -48,6 +48,15 @@ function Create-ModulePsm1 $template = $template -replace "%DATE%", [string](Get-Date) $template = $template -replace "%STRICT-DEPENDENCIES%", $strict $template = $template -replace "%DEPENDENCIES%", $loose + + $nestedModules = $module.NestedModules + $dllModules = "@(" + $nestedModules | ForEach-Object { + $dllModules += "'./" + $_ + ".dll'," + } + $dllModules += ")" + $template = $template -replace "%NESTED-MODULES%", $dllModules + Write-Host "Writing psm1 manifest to $templateOutputPath" $template | Out-File -FilePath $templateOutputPath -Force $file = Get-Item -Path $templateOutputPath @@ -57,7 +66,7 @@ function Create-ModulePsm1 if ([string]::IsNullOrEmpty($buildConfig)) { Write-Verbose "Setting build configuration to 'Release'" - $buildConfig = "Release" + $buildConfig = "Debug" } if ([string]::IsNullOrEmpty($scope)) From d41cfb1254bc8114488e1f04958386f066b37774 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Wed, 1 Nov 2017 13:32:41 -0700 Subject: [PATCH 5/9] move script to build folder --- .../Commands.Resources.csproj | 3 - .../StartupScripts/DefaultResourceGroup.psm1 | 39 ---------- tools/AzureRM.Example.psm1 | Bin 3764 -> 1356 bytes tools/AzureRM/AzureRM.psm1 | Bin 34 -> 11594 bytes tools/UpdateModules.ps1 | 72 ++++++++++++++---- 5 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 diff --git a/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj b/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj index eefd5c8393fe..2999ad33869b 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj +++ b/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj @@ -173,9 +173,6 @@ - - Always - diff --git a/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 b/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 deleted file mode 100644 index 11dcb8969ca2..000000000000 --- a/src/ResourceManager/Resources/Commands.Resources/StartupScripts/DefaultResourceGroup.psm1 +++ /dev/null @@ -1,39 +0,0 @@ -# Set Default Resource Group for Resources cmdlets -$nestedModules = Test-ModuleManifest '../AzureRM.Profile.psd1' -$dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Management.ResourceManager.dll' -$Assembly = [Reflection.Assembly]::LoadFrom($dllPath) -$AllCmdlets = $Assembly.GetTypes() | where {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} - -$dllPath = '../../../../../Package/Debug/ResourceManager/AzureResourceManager/AzureRM.Resources/Microsoft.Azure.Commands.Resources.dll' -$Assembly = [Reflection.Assembly]::LoadFrom($dllPath) -$AllCmdlets += $Assembly.GetTypes() | where {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} - -$FilteredCommands = @() -$AllCmdlets | ForEach-Object { - $rgParameter = $_.GetProperties() | Where-Object {$_.Name -eq "ResourceGroupName"} - if ($rgParameter -ne $null) { - $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} - $isMandatory = $true - $parameterSets | ForEach-Object { - $hasParameterSet = $_.NamedArguments | where {$_.MemberName -eq "ParameterSetName"} - $MandatoryParam = $_.NamedArguments | where {$_.MemberName -eq "Mandatory"} - if (($hasParameterSet -ne $null) -or (!$MandatoryParam.TypedValue.Value)) { - $isMandatory = $false - } - } - if ($isMandatory) { - $FilteredCommands += $_ - } - } -} - -$FilteredCommands | ForEach-Object { - $input = $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").VerbName + "-" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").NounName + ":ResourceGroupName" - $global:PSDefaultParameterValues.Add($input, - { - $context = Get-AzureRmContext - if ($context.ExtendedProperties.ContainsKey("Default Resource Group")) { - $context.ExtendedProperties["Default Resource Group"] - } - }) -} diff --git a/tools/AzureRM.Example.psm1 b/tools/AzureRM.Example.psm1 index 56bb44630a03edf0dd6ae29f28c8f0bc7870c362..6a6d81fe48fb3ef85fd55092f8021dee16c8e4db 100644 GIT binary patch delta 50 zcmdlYdxmSnE2hc6xRk_g859^)8JrpX8GM1zk-?9_g&~+hb@F?z$jNtjycpv*>+`lU F0sv@`4U7N) literal 3764 zcmd5FGuf99av}#(m4?)@bAbJANPGQ$bp)L;-ecHE@Et*_BQvSt`xG|2crt?35p2@( zJGFeTpFGjWD#pIo=vPI$DNWrKcv+X0`sSjxll)bdb7?}N2dizxA;C^ty&Phfo{r@s zb_RG#R6=-0v?#M9yNYB}C9BYsV3)BZb7YBX73ZmCvWVdXr>U73(+lUhOdJ4K+Knx!fgiCZFjmwOi$csDiBY73!mg`W?Zi2>!ADhKOj{x^diFB?`rOlyf#h zVQnTrd8S;RC}M#Skxz(>Ozjn*!B|;oWO|~0)$wiB)xoY+4`W*1b(TWpw~ctL0=v)= zL$(bxV(1K{l*wpbPif9VA9oQC=s|>+M=i?}!_N3@Y&wJo1NEPgNAQBETj!0`vt?!# z*);?=;nWuLIYv$9yP9W}%hI`WfIVjn53Sp<$8DOgG~(<^M44P7waRnF$Ei( zv_pCe7TKqWTGyq)DCD_R%t?n( zJ~Md@9wWxc9?qW2$s1fFK zsySg5G8eS_u;>8Hq1F5;JZC>62b~5^mDOmOWha|PivH$t@_7GyZ}Zl({yD~z^Xrf; z=6+SP&#HN`Cfab(g`?DsCQPk&m#WD!{y5usZ}M~6SYrK-Yrk@lu3~Stj+wdjopMhn zxtoh=duI1(eRuOpU<@%j4d+mrLpJNyO|2bt#U|>NlZ{-r`%?@Yd2?dlVvTUJP(P;w zYuruo^n5Am6T3KR_p?r_e)iyJ2~||WH`i8c|BJs3oey!&-`YmggL9R9xd9JH=p5u@ z4IS#K_j*6ceRf~zjf>3kGlsU@eWEAdkQ?KGp;<-Vz9Vy-?ia`%=R5OhlIAP*`FhCe z3UME$PIvE*5D9N)*{RHFmA%ot$B7xbKxygUOpwDcNX_69Dt@{0^6_ov)8&(GUoFsO Nr?7uzR>kRi(_gKVTE+kX diff --git a/tools/AzureRM/AzureRM.psm1 b/tools/AzureRM/AzureRM.psm1 index 2e72cb29c40c3bfe111b527d48bfd1621c2b496f..1c8c29464ac10cde477338fb30a1217c70c36f4d 100644 GIT binary patch literal 11594 zcmc&)Yi}Dx6un=K#DB0#q^44BlF%wp35lf7h^DPbfDZ^Ezv7xCwre|q0R8L0Irn-jHD}9av?qZcPT9y%0SNW-&AI} zbB5;=eUg0dz8uJ3Xf?rmKLF!C-iR^dtCx5_#AgEB8GgHXt1UP31i#0S)4`JwB#j`4 z(w?fcv3|3~09QlYj}ham+pzgIv3K$JrR?bUp8oFZ-90?r5q>|CZx%iKa?!?j_ z;tui-+<#VO>ozpi0x2UqN!d<}Ny*6tU!_ESoa>>tBc#ti+yXyHg3YINpX&OY|^ zb0qr;az>i>;%t*I)f-(V^$>P;FuLNCytmW}c~$;jQ+(ONWi z&6iJ+uQ)^GODg9@&P;tsV%8jJPW6t{uVJy*Rz~U=al_f78k>j6KvycY$oOEd?v=8W z{v7I`Y9-L2$&N%Gvv<{qc`p}4aOi;sw>fraoGuTU;U*N+U zg0oUI=WjaRZ{7GtpW1JdsrJ{WjW8LnifdTl6h^GnP$`rTTpK4xS(jGLb__e~w6RYriwr!se-R8JtyS2RayQbK_zIHmgAs zo~d&EN{?{dO~JHTW(=#r%6oyiriwbB7Lo%cpBm2jlpFCUI>*qn#<`K>4XwfaGfT8) z=J@h5KIQr~(!kiYLs%b{-I&k)wP0E**K=)nfI5VF-M@-FfgJJ$*~}6mxonJmKn@R) zQ?^fSZB`Xy%eCMH9&KTE_!MhX^6&k?xGm?|Q`p%;RbX{Na>Rz^i*nL`gpJmx2e7xV zKJVj>?Uigku6{-zbLDO0CoE5-EoPnhQLD`!M#2<$yt9rykYW{Vc2}cVYpcWKNT)}Z z_bG~D=I?tH!;5shYcIivw!Ayw!AaIj-uA}e`&uVCc@Khd?7o(HthpC8UV(ZMmYHoo z(kiZcJ*b?$lkBqxHR3dv`Q&w>8ADtK?QYI@9jGyj>qEPZm-Qhr`aCUT9y8)j%c0l` z--EHtZ+cL&D|{bD%t3nEXIVuLMwTb^V65id){mHG^1S%@+?)?NV%t2e)BKqaVKpP> z!3^WLJjknAD-U9JwU}PP`f^tuW|~>@YMteZyg0`Gcw49W91qGeL*qjs*J5m9a{U&a zu_=R@p@FLvJE_e_lzQEV^ZU(@Ew|Y(QLCmhwiNTMp zyLq*R6BJwnkvE`cyL!&_66_7nlXOvu)#Y1!zFVB&3~lufTD<^sJHbwYanlX#Oto?P zkt{xUd~K~?gARRYFv2tLYdmqBGd+N&U1+!^zsWE_evm%_4tU3j;KD6-SR)ZpX%468-f|7-Z7 AHUIzs literal 34 pcmY#Z2*^oHPR+>ANl7hINXsu$C{8ZQEGSVZNzE Date: Wed, 1 Nov 2017 13:41:24 -0700 Subject: [PATCH 6/9] revert changes --- .../Commands.Resources.csproj | 11 +++++++---- tools/AzureRM/AzureRM.psm1 | Bin 11594 -> 68 bytes 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj b/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj index 2999ad33869b..ae5afc12a130 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj +++ b/src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj @@ -188,10 +188,13 @@ - - - - + + + + \ No newline at end of file diff --git a/tools/AzureRM/AzureRM.psm1 b/tools/AzureRM/AzureRM.psm1 index 1c8c29464ac10cde477338fb30a1217c70c36f4d..ef11ce70483e591005de33ac2b94f28950523cd8 100644 GIT binary patch literal 68 zcmezWPnki1A%G!=A(0`OA(bJ6As@(20kVpK;%Pu0h%N@o6)|Ko6fl$kc_l#ETp$~y H2gC*d5@ZfM literal 11594 zcmc&)Yi}Dx6un=K#DB0#q^44BlF%wp35lf7h^DPbfDZ^Ezv7xCwre|q0R8L0Irn-jHD}9av?qZcPT9y%0SNW-&AI} zbB5;=eUg0dz8uJ3Xf?rmKLF!C-iR^dtCx5_#AgEB8GgHXt1UP31i#0S)4`JwB#j`4 z(w?fcv3|3~09QlYj}ham+pzgIv3K$JrR?bUp8oFZ-90?r5q>|CZx%iKa?!?j_ z;tui-+<#VO>ozpi0x2UqN!d<}Ny*6tU!_ESoa>>tBc#ti+yXyHg3YINpX&OY|^ zb0qr;az>i>;%t*I)f-(V^$>P;FuLNCytmW}c~$;jQ+(ONWi z&6iJ+uQ)^GODg9@&P;tsV%8jJPW6t{uVJy*Rz~U=al_f78k>j6KvycY$oOEd?v=8W z{v7I`Y9-L2$&N%Gvv<{qc`p}4aOi;sw>fraoGuTU;U*N+U zg0oUI=WjaRZ{7GtpW1JdsrJ{WjW8LnifdTl6h^GnP$`rTTpK4xS(jGLb__e~w6RYriwr!se-R8JtyS2RayQbK_zIHmgAs zo~d&EN{?{dO~JHTW(=#r%6oyiriwbB7Lo%cpBm2jlpFCUI>*qn#<`K>4XwfaGfT8) z=J@h5KIQr~(!kiYLs%b{-I&k)wP0E**K=)nfI5VF-M@-FfgJJ$*~}6mxonJmKn@R) zQ?^fSZB`Xy%eCMH9&KTE_!MhX^6&k?xGm?|Q`p%;RbX{Na>Rz^i*nL`gpJmx2e7xV zKJVj>?Uigku6{-zbLDO0CoE5-EoPnhQLD`!M#2<$yt9rykYW{Vc2}cVYpcWKNT)}Z z_bG~D=I?tH!;5shYcIivw!Ayw!AaIj-uA}e`&uVCc@Khd?7o(HthpC8UV(ZMmYHoo z(kiZcJ*b?$lkBqxHR3dv`Q&w>8ADtK?QYI@9jGyj>qEPZm-Qhr`aCUT9y8)j%c0l` z--EHtZ+cL&D|{bD%t3nEXIVuLMwTb^V65id){mHG^1S%@+?)?NV%t2e)BKqaVKpP> z!3^WLJjknAD-U9JwU}PP`f^tuW|~>@YMteZyg0`Gcw49W91qGeL*qjs*J5m9a{U&a zu_=R@p@FLvJE_e_lzQEV^ZU(@Ew|Y(QLCmhwiNTMp zyLq*R6BJwnkvE`cyL!&_66_7nlXOvu)#Y1!zFVB&3~lufTD<^sJHbwYanlX#Oto?P zkt{xUd~K~?gARRYFv2tLYdmqBGd+N&U1+!^zsWE_evm%_4tU3j;KD6-SR)ZpX%468-f|7-Z7 AHUIzs From 647691d642cb9d5690c5c76429c37358d84071e2 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Wed, 1 Nov 2017 16:56:18 -0700 Subject: [PATCH 7/9] base changes on Cormac's PR --- tools/AzureRM.Example.psm1 | Bin 1356 -> 1076 bytes tools/UpdateModules.ps1 | 72 ++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/tools/AzureRM.Example.psm1 b/tools/AzureRM.Example.psm1 index 6a6d81fe48fb3ef85fd55092f8021dee16c8e4db..ffbfe8a1bdb49cb2003a3896d3e65f24190831ea 100644 GIT binary patch delta 40 wcmX@ZwS{BDEJk5f22TcGh5!bCh9HIz23H0b2HnZ~ndB#HFl%h)VRm2w0Lg#}1ONa4 delta 308 zcmZus%?bfw6g}UpMC`376lLt}6&4mGWRLmi6Nd4(&@>M*JMW+rYfs>DJb*Jd3rb(z z@7#0GJ@?*w>>0nFRggm#EiAEy3lBSH4m2~3m7o=_OD8L>xhL&gYl$Q;Oc zqHw7xlQEb|j9iU4jIiKyairEk67k?8Dk6_A`WXJ03^2l&4H}g{)e73I&t>r}Y_6p_ zsESf#jFZFyJqPIV#5#W)4K(T0L`P5u;X|d;zDP9(ZE5k<99~pL`C-DcZ!cA|-tWaX A5&!@I diff --git a/tools/UpdateModules.ps1 b/tools/UpdateModules.ps1 index 28b971946f6b..dd287d61e286 100644 --- a/tools/UpdateModules.ps1 +++ b/tools/UpdateModules.ps1 @@ -32,31 +32,47 @@ function Create-ModulePsm1 PROCESS { - $manifestDir = Get-Item -Path $ModulePath - $moduleName = $manifestDir.Name + ".psd1" - $manifestPath = Join-Path -Path $ModulePath -ChildPath $moduleName - $module = Test-ModuleManifest -Path $manifestPath + $manifestDir = Get-Item -Path $ModulePath + $moduleName = $manifestDir.Name + ".psd1" + $manifestPath = Join-Path -Path $ModulePath -ChildPath $moduleName + $file = Get-Item $manifestPath + Import-LocalizedData -BindingVariable ModuleMetadata -BaseDirectory $file.DirectoryName -FileName $file.Name $templateOutputPath = $manifestPath -replace ".psd1", ".psm1" - [string]$strict - [string]$loose - foreach ($mod in $module.RequiredModules) + [string]$importedModules + if ($ModuleMetadata.RequiredModules -ne $null) { - $strict += " Import-Module " + $mod.Name + " -RequiredVersion " + [string]$mod.Version + "`r`n" - $loose += " Import-Module " + $mod.Name + "`r`n" + foreach ($mod in $ModuleMetadata.RequiredModules) + { + if ($mod["ModuleVersion"]) + { + $importedModules += Create-MinimumVersionEntry -ModuleName $mod["ModuleName"] -MinimumVersion $mod["ModuleVersion"] + } + elseif ($mod["RequiredVersion"]) + { + $importedModules += "Import-Module " + $mod["ModuleName"] + " -RequiredVersion " + $mod["RequiredVersion"] + "`r`n" + } + } } + + if ($ModuleMetadata.NestedModules -ne $null) + { + foreach ($dll in $ModuleMetadata.NestedModules) + { + $importedModules += "Import-Module (Join-Path -Path `$PSScriptRoot -ChildPath " + $dll.Substring(2) + ")`r`n" + } + } + $template = Get-Content -Path $TemplatePath - $template = $template -replace "%MODULE-NAME%", $module.Name + $template = $template -replace "%MODULE-NAME%", $file.BaseName $template = $template -replace "%DATE%", [string](Get-Date) - $template = $template -replace "%STRICT-DEPENDENCIES%", $strict - $template = $template -replace "%DEPENDENCIES%", $loose + $template = $template -replace "%IMPORTED-DEPENDENCIES%", $importedModules if ($AddDefaultParameters) { - $nestedModules = $module.NestedModules + $nestedModules = $ModuleMetadata.NestedModules $AllCmdlets = @() $nestedModules | ForEach-Object { - $dllName = $_.Name + ".dll" - $dllPath = Join-Path -Path $ModulePath -ChildPath $dllName + $dllPath = Join-Path -Path $ModulePath -ChildPath $_ $Assembly = [Reflection.Assembly]::LoadFrom($dllPath) $dllCmdlets = $Assembly.GetTypes() | Where-Object {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} $AllCmdlets += $dllCmdlets @@ -105,10 +121,33 @@ function Create-ModulePsm1 } } +function Create-MinimumVersionEntry +{ + [CmdletBinding()] + param( + [string]$ModuleName, + [string]$MinimumVersion + ) + + PROCESS + { + return "`$module = Get-Module $ModuleName ` +if (`$module -ne `$null -and `$module.Version.ToString().CompareTo(`"$MinimumVersion`") -lt 0) ` +{ ` + Write-Warning `"A later version of $ModuleName was found to be imported already. Please see for more details.`" ` + Write-Error `"A later version of $ModuleName was found to be imported already. Please see for more details.`" ` +} ` +elseif (`$module -eq `$null) ` +{ ` + Import-Module $ModuleName -MinimumVersion $MinimumVersion -Scope Global ` +}`r`n" + } +} + if ([string]::IsNullOrEmpty($buildConfig)) { Write-Verbose "Setting build configuration to 'Release'" - $buildConfig = "Debug" + $buildConfig = "Release" } if ([string]::IsNullOrEmpty($scope)) @@ -196,4 +235,3 @@ if (($scope -eq 'All') -or ($scope -eq 'AzureRM')) { } } - From c3eb2d0f429eec6e9a95278c905700db93da4221 Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Fri, 3 Nov 2017 11:23:29 -0700 Subject: [PATCH 8/9] Address review comments --- tools/AzureRM.Example.psm1 | 20 +++++--- tools/UpdateModules.ps1 | 101 +++++++++++++++++++++++-------------- 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/tools/AzureRM.Example.psm1 b/tools/AzureRM.Example.psm1 index cea741faa043..54e521847ffb 100644 --- a/tools/AzureRM.Example.psm1 +++ b/tools/AzureRM.Example.psm1 @@ -9,12 +9,16 @@ $PSDefaultParameterValues.Clear() Set-StrictMode -Version Latest -# Import dependencies using required version, if it is allowed -if ($PSVersionTable.PSVersion.Major -ge 5) -{ -%STRICT-DEPENDENCIES% -} -else -{ -%DEPENDENCIES% +%IMPORTED-DEPENDENCIES% + +$FilteredCommands = %COMMANDS% + +$FilteredCommands | ForEach-Object { + $global:PSDefaultParameterValues.Add($_, + { + $context = Get-AzureRmContext + if ($context.ExtendedProperties.ContainsKey("Default Resource Group")) { + $context.ExtendedProperties["Default Resource Group"] + } + }) } \ No newline at end of file diff --git a/tools/UpdateModules.ps1 b/tools/UpdateModules.ps1 index dd287d61e286..320be44f5d49 100644 --- a/tools/UpdateModules.ps1 +++ b/tools/UpdateModules.ps1 @@ -67,8 +67,27 @@ function Create-ModulePsm1 $template = $template -replace "%DATE%", [string](Get-Date) $template = $template -replace "%IMPORTED-DEPENDENCIES%", $importedModules - if ($AddDefaultParameters) - { + $contructedCommands = Find-DefaultResourceGroupCmdlets -AddDefaultParameters $AddDefaultParameters -ModuleMetadata $ModuleMetadata -ModulePath $ModulePath + $template = $template -replace "%COMMANDS%", $contructedCommands + + Write-Host "Writing psm1 manifest to $templateOutputPath" + $template | Out-File -FilePath $templateOutputPath -Force + $file = Get-Item -Path $templateOutputPath + } +} + +function Find-DefaultResourceGroupCmdlets +{ + [CmdletBinding()] + param( + [bool]$AddDefaultParameters, + [Hashtable]$ModuleMetadata, + [string]$ModulePath + ) + PROCESS + { + if ($AddDefaultParameters) + { $nestedModules = $ModuleMetadata.NestedModules $AllCmdlets = @() $nestedModules | ForEach-Object { @@ -78,47 +97,55 @@ function Create-ModulePsm1 $AllCmdlets += $dllCmdlets } - $FilteredCommands = @() - $AllCmdlets | ForEach-Object { - $rgParameter = $_.GetProperties() | Where-Object {$_.Name -eq "ResourceGroupName"} - if ($rgParameter -ne $null) { - $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} - $isMandatory = $true - $parameterSets | ForEach-Object { - $hasParameterSet = $_.NamedArguments | Where-Object {$_.MemberName -eq "ParameterSetName"} - $MandatoryParam = $_.NamedArguments | Where-Object {$_.MemberName -eq "Mandatory"} - if (($hasParameterSet -ne $null) -or (!$MandatoryParam.TypedValue.Value)) { - $isMandatory = $false - } - } - if ($isMandatory) { - $FilteredCommands += $_ - } + $FilteredCommands = $AllCmdlets | Where-Object {Test-RequiredParameter -Cmdlet $_} + + if ($FilteredCommands.Length -eq 0) { + $contructedCommands = "@()" + } + else { + $contructedCommands = "@(" + $FilteredCommands | ForEach-Object { + $contructedCommands += "'" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").VerbName + "-" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").NounName + ":ResourceGroupName" + "'," } + $contructedCommands = $contructedCommands -replace ".$",")" } - - if ($FilteredCommands.Length -eq 0) { - $contructedCommands = "@()" + + return $contructedCommands } + else { - $contructedCommands = "@(" - $FilteredCommands | ForEach-Object { - $contructedCommands += "'" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").VerbName + "-" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").NounName + ":ResourceGroupName" + "'," - } - $contructedCommands = $contructedCommands -replace ".$",")" + return "@()" } - - $template = $template -replace "%COMMANDS%", $contructedCommands - } + } +} - else { - $template = $template -replace "%COMMANDS%", "@()" - } - - Write-Host "Writing psm1 manifest to $templateOutputPath" - $template | Out-File -FilePath $templateOutputPath -Force - $file = Get-Item -Path $templateOutputPath - } +function Test-RequiredParameter +{ + [CmdletBinding()] + param( + [Object]$Cmdlet + ) + + PROCESS + { + $rgParameter = $Cmdlet.GetProperties() | Where-Object {$_.Name -eq "ResourceGroupName"} + if ($rgParameter -ne $null) { + $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} + $isMandatory = $true + $parameterSets | ForEach-Object { + $hasParameterSet = $_.NamedArguments | Where-Object {$_.MemberName -eq "ParameterSetName"} + $MandatoryParam = $_.NamedArguments | Where-Object {$_.MemberName -eq "Mandatory"} + if (($hasParameterSet -ne $null) -or (!$MandatoryParam.TypedValue.Value)) { + $isMandatory = $false + } + } + if ($isMandatory) { + return $true + } + } + + return $false + } } function Create-MinimumVersionEntry From 0fa53f9013f85709114df74cfd1457404e8e9b8e Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Mon, 6 Nov 2017 15:49:10 -0800 Subject: [PATCH 9/9] address PR comments --- tools/AzureRM.Example.psm1 | 2 +- tools/UpdateModules.ps1 | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/AzureRM.Example.psm1 b/tools/AzureRM.Example.psm1 index 3ab512b918af..5bd1f9c33eb1 100644 --- a/tools/AzureRM.Example.psm1 +++ b/tools/AzureRM.Example.psm1 @@ -17,7 +17,7 @@ $FilteredCommands | ForEach-Object { $global:PSDefaultParameterValues.Add($_, { $context = Get-AzureRmContext - if ($context.ExtendedProperties.ContainsKey("Default Resource Group")) { + if (($context -ne $null) -and $context.ExtendedProperties.ContainsKey("Default Resource Group")) { $context.ExtendedProperties["Default Resource Group"] } }) diff --git a/tools/UpdateModules.ps1 b/tools/UpdateModules.ps1 index 6cc6f43bc28d..73190cb68c46 100644 --- a/tools/UpdateModules.ps1 +++ b/tools/UpdateModules.ps1 @@ -97,7 +97,7 @@ function Find-DefaultResourceGroupCmdlets $AllCmdlets += $dllCmdlets } - $FilteredCommands = $AllCmdlets | Where-Object {Test-RequiredParameter -Cmdlet $_} + $FilteredCommands = $AllCmdlets | Where-Object {Test-CmdletRequiredParameter -Cmdlet $_ -Parameter "ResourceGroupName"} if ($FilteredCommands.Length -eq 0) { $contructedCommands = "@()" @@ -119,20 +119,21 @@ function Find-DefaultResourceGroupCmdlets } } -function Test-RequiredParameter +function Test-CmdletRequiredParameter { [CmdletBinding()] param( - [Object]$Cmdlet + [Object]$Cmdlet, + [string]$Parameter ) PROCESS { - $rgParameter = $Cmdlet.GetProperties() | Where-Object {$_.Name -eq "ResourceGroupName"} + $rgParameter = $Cmdlet.GetProperties() | Where-Object {$_.Name -eq $Parameter} if ($rgParameter -ne $null) { - $parameterSets = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} + $parameterAttributes = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} $isMandatory = $true - $parameterSets | ForEach-Object { + $parameterAttributes | ForEach-Object { $hasParameterSet = $_.NamedArguments | Where-Object {$_.MemberName -eq "ParameterSetName"} $MandatoryParam = $_.NamedArguments | Where-Object {$_.MemberName -eq "Mandatory"} if (($hasParameterSet -ne $null) -or (!$MandatoryParam.TypedValue.Value)) {