Invoke-Command Enable-IISConfig Password Invalid ErrorRSS

1 reply

Last post May 08, 2019 06:57 AM by Jalpa Panchal

  • Invoke-Command Enable-IISConfig Password Invalid Error

    May 07, 2019 08:31 AM|BradSherwin|LINK

    Hi Guys,

    I'm having a bit of trouble with some PS code I've been working on.  The error I'm getting is:

    Invalid password
    + CategoryInfo : NotSpecified: (:) [Enable-IISSharedConfig], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.IIS.Powershell.Commands.EnableIISSharedConfigCommand
    + PSComputerName : ISSERVER06

    Here is my code and I get the same error for all the servers.

    $serverlist = @("ISSERVER04","ISSERVER05","ISSERVER06")
    
    $sharedconfig = "\\DOMAIN\dfs\IISCentralConfig"
    
    $Credentials = (Get-Credential -Message "Please enter the Login credentials for app pool inc domian name").GetNetworkCredential()
    
    $username = $Credentials.Domain + "\" + $Credentials.UserName
    
    $password = $Credentials.SecurePassword
    
    $sharedconfigpassword = Read-Host -AsSecureString -Prompt "Please Enter a password for encrypting the IIS config."
    
    
    Export-IISConfiguration -PhysicalPath "C:\IISExport" -KeyEncryptionPassword $sharedconfigpassword
    
    Move-Item -Path "C:\IISExport\*" -Destination $sharedconfig -Force
    
    
    #Enable IIS Shared Configuration for each web server
    
    $sb2 = {
            
                Enable-IISSharedConfig -PhysicalPath $args[0] -UserName $args[1] -Password $args[2] -KeyEncryptionPassword $args[3]
    
    }
    
    foreach ($server in $serverlist){
    
    Invoke-Command -ComputerName $server -ArgumentList $sharedconfig,$username,$password,$sharedconfigpassword -ScriptBlock $sb2 -Force
    
    }

    I've tested manually on each web server with the credentials and they work just fine.  Also, if I run Enable-IISConfig on the local server I'm working from it works so I believe its the invoke-command.  I've ran $password.GetType and I can see its a SecureString.

    The account I'm running this PS script from is my domain admin account too.

    Any ideas,

    Appreciate the help.

    Brad

  • Re: Invoke-Command Enable-IISConfig Password Invalid Error

    May 08, 2019 06:57 AM|Jalpa Panchal|LINK

    Hi,

    Try to use get credentials and store that detail in variable and use in invoke command or just try to access this command and check the result.

    BradSherwin

    Invoke-Command -ComputerName $server -ArgumentList $sharedconfig,$username,$password,$sharedconfigpassword -ScriptBlock $sb2 -Force

    $cred = Get-credential
    $script = {Write-Host "test!"}
    invoke-command -computername "mypc2" -Credential $cred -scriptblock $script -ErrorAction Silentlycontinue
    if (!$?)
    {
      if ($error[0].FullyQualifiedErrorId -eq "PSSessionStateBroken")
      {"Wrong User/Password"}
    }

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.