@@ -1604,8 +1604,11 @@ public bool GetNamedArgumentAttributeValue(NamedAttributeArgumentAst namedAttrib
1604
1604
1605
1605
public static IEnumerable < string > GetModuleManifestKeys ( Version powershellVersion )
1606
1606
{
1607
+ if ( powershellVersion == null )
1608
+ {
1609
+ throw new ArgumentNullException ( "powershellVersion" ) ;
1610
+ }
1607
1611
var keys = new List < string > ( ) ;
1608
-
1609
1612
var keysCommon = new List < string > {
1610
1613
"RootModule" ,
1611
1614
"ModuleVersion" ,
@@ -1635,25 +1638,31 @@ public static IEnumerable<string> GetModuleManifestKeys(Version powershellVersio
1635
1638
"PrivateData" ,
1636
1639
"HelpInfoURI" ,
1637
1640
"DefaultCommandPrefix" } ;
1638
-
1639
1641
keys . AddRange ( keysCommon ) ;
1640
-
1641
- // default to version 5.0
1642
- if ( powershellVersion == null || powershellVersion . Equals ( new Version ( "5.0" ) ) )
1642
+ if ( powershellVersion . Equals ( new Version ( "5.0" ) ) )
1643
1643
{
1644
1644
keys . Add ( "DscResourcesToExport" ) ;
1645
1645
}
1646
+ else if ( ! powershellVersion . Equals ( new Version ( "4.0" ) )
1647
+ && ! powershellVersion . Equals ( new Version ( "3.0" ) ) )
1648
+ {
1649
+ throw new ArgumentException ( "Invalid PowerShell version. Choose from 3.0, 4.0 or 5.0" ) ;
1650
+ }
1646
1651
return keys ;
1647
1652
}
1648
1653
1649
- public static bool IsModuleManifest ( string filepath )
1654
+ public static bool IsModuleManifest ( string filepath , Version powershellVersion )
1650
1655
{
1651
1656
Token [ ] tokens ;
1652
1657
ParseError [ ] errors ;
1653
1658
if ( filepath == null )
1654
1659
{
1655
1660
throw new ArgumentNullException ( "filepath" ) ;
1656
1661
}
1662
+ if ( powershellVersion == null )
1663
+ {
1664
+ throw new ArgumentNullException ( "powershellVersion" ) ;
1665
+ }
1657
1666
if ( ! Path . GetExtension ( filepath ) . Equals ( ".psd1" , StringComparison . OrdinalIgnoreCase ) )
1658
1667
{
1659
1668
return false ;
@@ -1667,7 +1676,9 @@ public static bool IsModuleManifest(string filepath)
1667
1676
{
1668
1677
return false ;
1669
1678
}
1670
- var keys = GetModuleManifestKeys ( null ) ;
1679
+ var keys = GetModuleManifestKeys ( powershellVersion ) ;
1680
+
1681
+ // check if all the keys in hast.keyvaluepairs are present in keys
1671
1682
int matchCount = 0 ;
1672
1683
foreach ( var pair in hast . KeyValuePairs )
1673
1684
{
0 commit comments