Skip to content

Commit b07f24e

Browse files
iSazonovdaxian-dbw
authored andcommitted
Exclude '-Comobject' parameter of 'New-Object' on unsupported platforms (PowerShell#4922)
1 parent 99e3fe5 commit b07f24e

File tree

2 files changed

+187
-174
lines changed

2 files changed

+187
-174
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/new-object.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public sealed class NewObjectCommand : PSCmdlet
3131
[Parameter(ParameterSetName = netSetName, Mandatory = true, Position = 0)]
3232
public string TypeName { get; set; } = null;
3333

34-
34+
#if !UNIX
3535
private Guid _comObjectClsId = Guid.Empty;
3636
/// <summary> the ProgID of the Com object</summary>
3737
[Parameter(ParameterSetName = "Com", Mandatory = true, Position = 0)]
3838
public string ComObject { get; set; } = null;
39-
39+
#endif
4040

4141
/// <summary>
4242
/// The parameters for the constructor
@@ -245,6 +245,7 @@ protected override void BeginProcessing()
245245
"CannotFindAppropriateCtor",
246246
ErrorCategory.ObjectNotFound, null));
247247
}
248+
#if !UNIX
248249
else // Parameterset -Com
249250
{
250251
int result = NewObjectNativeMethods.CLSIDFromProgID(ComObject, out _comObjectClsId);
@@ -295,10 +296,12 @@ protected override void BeginProcessing()
295296
}
296297
WriteObject(comObject);
297298
}
299+
#endif
298300
}//protected override void BeginProcessing()
299301

300302
#endregion Overrides
301303

304+
#if !UNIX
302305
#region Com
303306

304307
private object SafeCreateInstance(Type t, object[] args)
@@ -467,6 +470,7 @@ private object CreateComObject()
467470
}
468471

469472
#endregion Com
473+
#endif
470474

471475
// HResult code '-2147417850' - Cannot change thread mode after it is set.
472476
private const int RPC_E_CHANGED_MODE = unchecked((int)0x80010106);

0 commit comments

Comments
 (0)