Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Rules/UseCompatibleCmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private struct RuleParameters
private bool hasInitializationError;
private string reference;
private readonly string defaultReference = "desktop-5.1.14393.206-windows";
private readonly string alternativeDefaultReference = "core-6.0.2-windows";
private RuleParameters ruleParameters;

public UseCompatibleCmdlets()
Expand Down Expand Up @@ -274,6 +275,10 @@ private void SetupCmdletsDictionary()

ruleParameters.compatibility = compatibilityList.ToArray();
reference = defaultReference;
if (compatibilityList.Count == 1 && compatibilityList[0] == defaultReference)
{
reference = alternativeDefaultReference;
}
#if DEBUG
// Setup reference file
object referenceObject;
Expand Down Expand Up @@ -326,7 +331,7 @@ private void SetupCmdletsDictionary()
return;
}

var extentedCompatibilityList = compatibilityList.Concat(Enumerable.Repeat(reference, 1));
var extentedCompatibilityList = compatibilityList.Union(Enumerable.Repeat(reference, 1));
foreach (var compat in extentedCompatibilityList)
{
string psedition, psversion, os;
Expand Down
5 changes: 5 additions & 0 deletions Tests/Rules/UseCompatibleCmdlets.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ Describe "UseCompatibleCmdlets" {
@("Start-VM", "New-SmbShare", "Get-Disk") | `
Test-Command -Settings $settings -ExpectedViolations 1
}

Context "Default reference can also be used as target platform" {
$settings = @{rules=@{PSUseCompatibleCmdlets=@{compatibility=@("desktop-5.1.14393.206-windows")}}}
@("Remove-Service") | Test-Command -Settings $settings -ExpectedViolations 1
}
}