locked
Unable to delete Ophaned Windows Server AD User accounts RRS feed

  • Question

  • I'm Trying to remove Orphaned User amounts from Azure AD

    When trying to do this using the following procedure

    Step 1

      Install-Module -Name MSOnline
      Connect-MsolService

    Login Fails

    Step 2

    AZ

    AZ Login

    You have logged in. Now let us find all the subscriptions to which you have access...
    [
      {
        "cloudName": "AzureCloud",
        "id": "cff169e3-xxxx-xxxx-88ef-e4d204d0e0ac",
        "isDefault": true,
        "name": "Free Trial",
        "state": "Enabled",
        "tenantId": "37bd401c-e353-xxxx-xxxx-e5eaebaab700",
        "user": {
          "name": "stuart.honour@xxx.org",
          "type": "user"
        }
      }
    ]

    Step 3

    $msolcred = get-credential connect-msolservice -credential $msolcred

    Error

    Get-Credential : A positional parameter cannot be found that accepts argument 'connect-msolservice'.
    At line:1 char:13
    + $msolcred = get-credential connect-msolservice -credential $msolcred
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-Credential], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetCredentialCommand 

    so i can never run this command Remove-MsolUser UserPrincipalName "account@account.com"



    • Edited by S Honour Tuesday, July 2, 2019 8:34 PM
    Tuesday, July 2, 2019 8:29 PM

Answers

  • I have resolved this issue now by using base command and responses 

    Connect-MsolService

    Remove-MsolUser

    cmdlet Remove-MsolUser at command pipeline position 1
    Supply values for the following parameters:
    ObjectId: c5965725-afe5-xxxx-xxxx-a84cfb4b4ca1

    Confirm
    Continue with this operation?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

    Object removed 

    Tuesday, July 2, 2019 9:07 PM

All replies

  • I have resolved this issue now by using base command and responses 

    Connect-MsolService

    Remove-MsolUser

    cmdlet Remove-MsolUser at command pipeline position 1
    Supply values for the following parameters:
    ObjectId: c5965725-afe5-xxxx-xxxx-a84cfb4b4ca1

    Confirm
    Continue with this operation?
    [Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

    Object removed 

    Tuesday, July 2, 2019 9:07 PM
  • I don't know why the other commands were not working
    Tuesday, July 2, 2019 9:08 PM
  • Your code thinks connect-msolservice is an argument for  get-credential. Use a new line to get it working. 

    $msolcred = get-credential
    connect-msolservice -credential $msolcred
    remove-msoluser


    Tuesday, July 2, 2019 9:20 PM