8000 Add module AccountManagement by iSazonov · Pull Request #9926 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Add module AccountManagement #9926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

iSazonov
Copy link
Collaborator

PR Summary

Add new module Microsoft.PowerShell.AccountManagement
There is only single cmdlet New-User to keep the PR as small as possible.
Later we will add other cmdlets.

PR Context

Related #2996

Module Microsoft.PowerShell.LocalAccounts was removed from PowerShell Core because of using non-public APIs.
Microsoft.PowerShell.AccountManagement uses only public APIs and based on System.DirectoryServices.AccountManagement.

It is impossible to get full backward compatibility with Microsoft.PowerShell.LocalAccounts module due to differences of the underlying API.
So the main model was chosen Microsoft ActiveDirectory module.
It will be easier for users to migrate from Microsoft.PowerShell.LocalAccounts to a more functional Microsoft.PowerShell.LocalAccounts module if necessary.

PR Checklist

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jun 18, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.2 milestone Jun 18, 2019
@TravisEz13
Copy link
Member

is the syntax the same as the windows PowerShell cmdlet?

@iSazonov
Copy link
Collaborator Author

@TravisEz13 No, as mentioned in the PR description the used API is another and it impossible to keep full backward compatibility. The new design is closer to ActiveDirectory module. It make more sense because scripts can works (manage accounts) without the need to install AdminTools everyware.
I did not look at this in detail, but it is quite possible that we could get almost the same functionality using the cmdlet aliases and parameters. I suppose it should stay outside of this module.

@iSazonov
Copy link
Collaborator Author

Last days CI Macos frequently time out.

@iSazonov iSazonov force-pushed the add-module-accountmanagement branch from 7d2f588 to bfc2136 Compare June 19, 2019 10:59
@iSazonov iSazonov marked this pull request as ready for review June 19, 2019 11:23
@iSazonov
Copy link
Collaborator Author

@SteveL-MSFT Can your team review so that we can move on and add more cmdlets in follow PRs?

@kilasuit
Copy link
Collaborator

IMO this should be externalised, released to the Gallery and pulled into the output build of PowerShell (like PowerShellGet) instead of being added to the codebase

@adityapatwardhan
Copy link
Member

I agree with @kilasuit. This should ideally go to PSGallery and be pulled down.

@iSazonov
Copy link
Collaborator Author

We have a base account management in Windows PowerShell many years. If plan is to replace Windows PowerShell with PowerShell 7.0 we need to get back most of common modules and features that we lost in porting time.

  • Please point me the community that is ready to take on the production of this module for all the necessary platforms. Over the past 3 years, I have repeatedly heard that we need to decouple modules. But where are the people who take it upon themselves? I am ready to make the module (and make other contributions) in the repo but I am not ready to take on the entire production cycle.

  • Currently I have 99.9% needed PowerShell features in-box on all my enterprise servers to manage the infrastructure. Today we (I say about enterprise) cannot replace Windows PowerShell with PowerShell Core because it is slow, consumes a lot of resources and, mostly, lost a lot of functionality. (I do not think that it is possible to fix it a few months before the 7.0 release.) We can not freely use third-party modules because strong enterprise policy - we can not trust whole Internet, validate every new version, we have isolated networks. PowerShell for us is an enterprise level management tool. If it will have not all we had many years we will have to spend time and money to implement/find workarounds (maybe write internal scripts to replace gaps or more likely to replace it with a better alternative management tool).

@vexx32
Copy link
Collaborator
vexx32 commented Jun 19, 2019

I don't think there's any necessary need to force these to be a completely separate module.

Maybe have a tracking issue or issues for such modules that we want to eventually have out of box? Separating them to a separately shipped module and/or pulling them into the PS build cycle isn't a huge undertaking in and of itself.

I don't see why we need reject this as it is at the present; we can always move to separate it to a separate module when someone willing to maintain and develop it further steps up, whether from the PS team or the community.

@SteveL-MSFT
Copy link
Member

I think we would want to include this as part of the PS7 package, but also think it should be a separate module that is published to PSGallery and have its own repo. Eventually, I want to split up and move Utility and Management modules out of this repo (see #9960). Since the code is all self contained in a single folder, I think it's ok to just keep it in this repo for now and we can move it out when we do so for the others. By that time, hopefully we'll have templatized how to create the repos, contributing docs/etc.., enable CI, etc...

Author="PowerShell"
CompanyName="Microsoft Corporation"
Copyright="Copyright (c) Microsoft Corporation. All rights reserved."
ModuleVersion="6.1.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to have module versions match the PowerShell version. This should really be 1.0.0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copyright="Copyright (c) Microsoft Corporation. All rights reserved."
ModuleVersion="6.1.0.0"
CompatiblePSEditions = @("Core")
PowerShellVersion="3.0"
Copy link
Member

Choose a reason for hiding this comment

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

This should be the minimum version that this works with which is probably 6.0. If it works with older than 6.0, then CompatiblePSEditions needs to include Desktop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

/// Gets or sets a DateTime that specifies the date and time that the account expires.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
[AllowNull]
Copy link
Member

Choose a reason for hiding this comment

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

Null here means never expires? But you have -AccountNeverExpires below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't work. Will remove.

{
get;
set;
} = ContextType.Domain;
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to be Domain by default? Does this work on non-Windows?

Copy link
Collaborator Author
@iSazonov iSazonov Jun 20, 2019

Choose a reason for hiding this comment

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

It is only Windows API. Although it is based on "providers" and we could get support Unix PAM or something like in future.

I choose the default as enterprise user to be close to New-ADUser cmdlet from ActiveDirectory module.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jun 20, 2019
@iSazonov iSazonov force-pushed the add-module-accountmanagement branch 2 times, most recently from ec60a8a to 6199946 Compare December 25, 2019 04:42
@iSazonov iSazonov force-pushed the add-module-accountmanagement branch from 6199946 to 48005be Compare December 25, 2019 05:42
@iSazonov iSazonov force-pushed the add-module-accountmanagement branch 3 times, most recently from 87e5837 to 36018bc Compare December 26, 2019 07:48
@iSazonov iSazonov force-pushed the add-module-accountmanagement branch 2 times, most recently from 50b8e23 to 776b13c Compare December 27, 2019 14:45
@@ -1964,6 +1964,11 @@
<File Id="fil6B026F6D5210498B99E5F14386F4F90B" KeyPath="yes" Source="$(env.ProductSourcePath)\Modules\ThreadJob\Microsoft.PowerShell.ThreadJob.dll" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

@iSazonov, your last commit had 7 failures in PowerShell-CI-windows
(These are 5 of the failures)

Validate AccountManagement user cmdlets.Validate New-User.Can create New-User with only name

Expected exactly 'TestUserNew', but got $null.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 27
27:                 $result.Name | Should -BeExactly TestUserNew

Validate AccountManagement user cmdlets.Validate New-User.Can create New-User with password

Expected exactly 'TestUserNew', but got $null.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 38
38:                 $result.Name | Should -BeExactly TestUserNew

Validate AccountManagement user cmdlets.Validate New-User.Can create New-User with explicit properties in local machine

Expected exactly 'samq2', but got $null.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 54
54:                 $result.Name | Should -BeExactly "samq2"

Validate AccountManagement user cmdlets.Validate Remove-User.Can remove user account with pipeline

Expected an exception, with FullyQualifiedErrorId 'UserAlreadyRemoved,Microsoft.PowerShell.Commands.RemoveUserCommand' to be thrown, but no exception was thrown.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 137
137:                 { $userIdentity | Remove-User -ErrorAction Stop } | Should -Throw -ErrorId "UserAlreadyRemoved,Microsoft.PowerShell.Commands.RemoveUserCommand"

Validate AccountManagement user cmdlets.Validate Remove-User.Can remove user account with parameter

Expected no exception to be thrown, but an exception "Cannot bind argument to parameter 'Identity' because it is null." was thrown from D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1:141 char:41
    +                 { Remove-User -Identity $userIdentity -ErrorAction St ?
    +                                         ~~~~~~~~~~~~~.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 141
141:                 { Remove-User -Identity $userIdentity -ErrorAction Stop } | Should -Not -Throw

@iSazonov iSazonov force-pushed the add-module-accountmanagement branch from 776b13c to 4384f8b Compare January 10, 2020 15:03
@iSazonov iSazonov force-pushed the add-module-accountmanagement branch from 56a4fd8 to 4384f8b Compare January 13, 2020 15:16
@@ -1964,6 +1964,11 @@
<File Id="fil6B026F6D5210498B99E5F14386F4F90B" KeyPath="yes" Source="$(env.ProductSourcePath)\Modules\ThreadJob\Microsoft.PowerShell.ThreadJob.dll" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

@iSazonov, your last commit had 7 failures in PowerShell-CI-windows
(These are 5 of the failures)

Validate AccountManagement user cmdlets.Validate New-User.Can create New-User with only name

Expected exactly 'TestUserNew', but got $null.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 27
27:                 $result.Name | Should -BeExactly TestUserNew

Validate AccountManagement user cmdlets.Validate New-User.Can create New-User with password

Expected exactly 'TestUserNew', but got $null.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 38
38:                 $result.Name | Should -BeExactly TestUserNew

Validate AccountManagement user cmdlets.Validate New-User.Can create New-User with explicit properties in local machine

Expected exactly 'samq2', but got $null.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 54
54:                 $result.Name | Should -BeExactly "samq2"

Validate AccountManagement user cmdlets.Validate Remove-User.Can remove user account with pipeline

Expected no exception to be thrown, but an exception "Cannot access a disposed object.
Object name: 'PrincipalContext'." was thrown from D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1:134 char:35
    + ?               { $userIdentity | Remove-User -ErrorAction Stop } | Sho ?
    +                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 134
134:                 { $userIdentity | Remove-User -ErrorAction Stop } | Should -Not -Throw

Validate AccountManagement user cmdlets.Validate Remove-User.Can remove user account with parameter

Expected no exception to be thrown, but an exception "Cannot bind argument to parameter 'Identity' because it is null." was thrown from D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1:141 char:41
    +                 { Remove-User -Identity $userIdentity -ErrorAction St ?
    +                                         ~~~~~~~~~~~~~.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.AccountManagement\AccountManagement.User.Tests.ps1: line 141
141:                 { Remove-User -Identity $userIdentity -ErrorAction Stop } | Should -Not -Throw

@ghost ghost added the Review - Needed The PR is being reviewed label May 27, 2020
@ghost
Copy link
ghost commented May 27, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@TravisEz13 TravisEz13 added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels May 27, 2020
@iSazonov
Copy link
Collaborator Author
iSazonov commented Jun 2, 2020

Closed with #12242 (comment)

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jun 2, 2020
@iSazonov iSazonov closed this Jun 2, 2020
@iSazonov iSazonov deleted the add-module-accountmanagement branch August 20, 2024 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0