Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Exclude -Comobject parameter of New-Object cmdlet on unsupported platforms#4922

Merged
daxian-dbw merged 5 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:comobject-excludeiSazonov/PowerShell:comobject-excludeCopy head branch name to clipboard
Sep 29, 2017
Merged

Exclude -Comobject parameter of New-Object cmdlet on unsupported platforms#4922
daxian-dbw merged 5 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:comobject-excludeiSazonov/PowerShell:comobject-excludeCopy head branch name to clipboard

Conversation

@iSazonov

Copy link
Copy Markdown
Collaborator

Fix #4897.

New-Object -Comobject is not supported on

  • Linux and MacOs - fix is remove the code.
  • Windows Core and IoT - fix is throw NotSupportedException exception.

First commit reformat test file.

{
if (!Platform.IsWindowsDesktop)
{
Exception exc = new NotSupportedException(NewObjectStrings.ComObjectPlatformIsNotSupported);

@daxian-dbw daxian-dbw Sep 26, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COM works on NanoServer as well, as long as it has a workable COM component
PS: the COM support was enabled when powershell core was still NanoServer powershell.

@iSazonov iSazonov Sep 26, 2017

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based on current tests. 😕
So should we exclude the parameter only on Unix?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The COM components we use in our tests are not available in NanoServer and IoT.
Yes, we should exclude the parameter only for Unix plats.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "Shell.Application" work on NanoServer and IoT? can I use this in a test?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell itself is not available on NanoServer and IoT. You can use it as a test, but just follow the existing tests in test\powershell\engine\COM.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why shouldn't we targeting our test to NanoServer and IoT?

}

#endif
#endregion Com

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the entire "com" region here should be under the #if !UNIX.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@PaulHigin PaulHigin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if ($IsLinux -or $IsMacOs ) {
{ New-Object -ComObject "Shell.Application" } | ShouldBeErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand"
} else {
{ New-Object -ComObject "Shell.Application" } | Should Not Throw

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail when running tests on NanoServer ... Maybe change it to check if New-Object has the parameter ComObject instead of creating the Shell.Application object?

$s = gcm New-Object
$s.Parameters.ContainsKey("ComObject")
True

@daxian-dbw daxian-dbw merged commit b07f24e into PowerShell:master Sep 29, 2017
@iSazonov iSazonov deleted the comobject-exclude branch September 29, 2017 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-ComObject should not be exposed on systems where it is not supported

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.