diff --git a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs
index 2c5c91fb1c8..a065f79204f 100644
--- a/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimQuery.cs
@@ -314,11 +314,7 @@ public override void FilterByAssociatedInstance(object associatedInstance, strin
///
public override void AddQueryOption(string optionName, object optionValue)
{
- if (string.IsNullOrEmpty(optionName))
- {
- throw new ArgumentNullException(nameof(optionName));
- }
-
+ ArgumentException.ThrowIfNullOrEmpty(optionName);
ArgumentNullException.ThrowIfNull(optionValue);
this.queryOptions[optionName] = optionValue;
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs
index 1b10bbfe7ab..035d5b17bbe 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/CIMHelper.cs
@@ -79,8 +79,7 @@ internal static string WqlQueryAll(string from)
///
internal static T GetFirst(CimSession session, string nameSpace, string wmiClassName) where T : class, new()
{
- if (string.IsNullOrEmpty(wmiClassName))
- throw new ArgumentException("String argument may not be null or empty", nameof(wmiClassName));
+ ArgumentException.ThrowIfNullOrEmpty(wmiClassName);
try
{
@@ -132,9 +131,8 @@ internal static string WqlQueryAll(string from)
///
internal static T[] GetAll(CimSession session, string nameSpace, string wmiClassName) where T : class, new()
{
- if (string.IsNullOrEmpty(wmiClassName))
- throw new ArgumentException("String argument may not be null or empty", nameof(wmiClassName));
-
+ ArgumentException.ThrowIfNullOrEmpty(wmiClassName);
+
var rv = new List();
try
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/PingPathCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/PingPathCommand.cs
index 9bebcd076ca..f5696712dd9 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/PingPathCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/PingPathCommand.cs
@@ -186,19 +186,21 @@ protected override void ProcessRecord()
{
bool result = false;
- if (path == null)
- {
- WriteError(new ErrorRecord(
- new ArgumentNullException(TestPathResources.PathIsNullOrEmptyCollection),
- "NullPathNotPermitted",
- ErrorCategory.InvalidArgument,
- Path));
- continue;
- }
-
if (string.IsNullOrWhiteSpace(path))
{
- WriteObject(result);
+ if (path is null)
+ {
+ WriteError(new ErrorRecord(
+ new ArgumentNullException(TestPathResources.PathIsNullOrEmptyCollection),
+ "NullPathNotPermitted",
+ ErrorCategory.InvalidArgument,
+ Path));
+ }
+ else
+ {
+ WriteObject(result);
+ }
+
continue;
}