Skip to content
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

[System.Web.Security] not support? #5352

Closed
SyuichiMurashima opened this issue Nov 6, 2017 · 6 comments
Closed

[System.Web.Security] not support? #5352

SyuichiMurashima opened this issue Nov 6, 2017 · 6 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered.

Comments

@SyuichiMurashima
Copy link

Steps to reproduce

Add-type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword(14, 5)

Expected behavior

Create random string


Actual behavior

Unable to find type [System.Web.Security.Membership].
At line:1 char:1

  • [System.Web.Security.Membership]::GeneratePassword(14, 5)
  •   + CategoryInfo          : InvalidOperation: (System.Web.Security.Membership:TypeName) [], RuntimeException
      + FullyQualifiedErrorId : TypeNotFound
    
    

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Microsoft Windows 10.0.17025
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@markekraus
Copy link
Contributor

.NET Core does not support System.Web.dll and there are apparently no plans to port it from .NET Framework to .NET Core as it is tightly dependent on IIS and .NET Core's aim is to be cross-platform compatible. Since PowerShell Core is built on .NET Core it wont be possible to use classes from System.Web.dll in PowerShell Core. You can search for comparable APIs using the .NET API browser. Many of the API's have been moved to ASP.NET Core.

it may be possible to directly reference the full path of System.Web.dll instead of the partial name. But I don't believe System.Web.dll is compatible with .NET Core and I haven't tried myself. You can experiment with that, but I believe the better course would be to try and find comparable API's in .NET Core and move your code to them.

@markekraus markekraus added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Nov 6, 2017
@SteveL-MSFT SteveL-MSFT added the Resolution-Answered The question is answered. label Nov 6, 2017
@ArmaanMcleod
Copy link
Contributor

ArmaanMcleod commented Jul 24, 2022

Another option could be convert [System.Web.Security.Membership]::GeneratePassword to powershell from source: https://referencesource.microsoft.com/#System.Web/Security/Membership.cs,302

Or just load a static type in with Add-Type.

@echalone
Copy link

echalone commented Aug 18, 2022

Hi guys, I've made the module Powershell Core compatible (since I needed it in Powershell Core myself) and renamed it TUN.CredentialManager.

I've reimplemented the GeneratePassword method from Microsoft as suggested by @ArmaanMcleod (thanks a lot, that helped!) and I've also experienced the problem that it didn't find the cmdlets if they weren't explicitly exported in the module manifest, which I've done now.

The module has a new name ( TUN.CredentialManager ) and new GUID since I cannot upload new versions to Dave's module in the Powershell Gallery. The new version should be backwards compatible to the old Powershell versions as well as compatible to the new Powershell Core. Since it uses the same cmdlet names you'd need to uninstall the old CredentialManager module first and then install the new TUN.CredentialManager module for everything to work properly. But nothing changed for the cmdlet calls, so this new TUN.CredentialManager module is backwards compatible to the old CredentialManager module by Dave, all you may need to change is the name of the module you import (if it wasn't installed). The versioning starts with 2.1 since the old CredentialManager stopped at 2.0. The copyright message was extended with my name and the new year, the license is unchanged (MIT).

The new TUN.CredentialManager module can be found here:
https://www.powershellgallery.com/packages/TUN.CredentialManager
https://github.com/echalone/PowerShell_Credential_Manager

And can simply be installed via...
Install-Module -Name TUN.CredentialManager

Provides access to credentials in the Windows Credential Manager (continuation of CredentialManager by Dave Garnar)
GitHub
PowerShell Module to Read and Write Credentials from the Windows Credential Manager - GitHub - echalone/PowerShell_Credential_Manager: PowerShell Module to Read and Write Credentials from the Windo...

@abdulhye
Copy link

Thank you so much @echalone !! it was really helpful as am about to use it

@echalone
Copy link

You're welcome :)
Maybe some have already noticed that I've updated it to version 3.0 by now and the module now uses SecureString internally where/when possible. Get-StoredCredential has the new switches ExcludeClearPassword and IncludeSecurePassword to exclude retrieving the password as clear text and/or to include retrieving the password as SecureString. Password length is now also supported up to 1280 unicode characters (up from 256 unicode characters).

@brianhildebrandt
Copy link

Thank you for picking up this solution and making it compatible with Core! I am working on a SharePoint project using PnP.Powershell and desperately needed this solution for my application! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered.
Projects
None yet
Development

No branches or pull requests

7 participants