locked
Authentication not working RRS feed

  • Question

  • I have this script that looks up if a user is a member of a security group before allowing them to proceed.  But its not working and stating that access is denied based on the script result:

    $username = "$($env:USERNAME)"
    
    $membersz = Invoke-Command -ComputerName pdc -Credential $mycreds -ScriptBlock {
    			Get-ADGroupMember -Identity "grpService" 
    		}				
    if ($membersz.SamAccountName -contains $username )
    {
    
    Start-Process -FilePath "y:\GVF_Dokumente.accde" -ArgumentList "/runtime"
    }
    
    else
    {
    
    Add-Type -AssemblyName System.Windows.Forms 
    $WaitForm = New-Object system.Windows.Forms.Form
    $WaitFormLabel = New-Object System.Windows.Forms.Label
    $WaitForm.Controls.Add($WaitFormLabel)
    $WaitFormLabel.Text = "Sorry access denied."
    $WaitFormLabel.location = new-object system.drawing.point(18,20)
    $WaitFormLabel.AutoSize = $True
    $WaitFormLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",10.25,[System.Drawing.FontStyle]::Bold)
    $WaitForm.BackColor = "#000000"
    $WaitForm.ForeColor = "#ffffff"
    $WaitForm.Width = 500
    $WaitForm.Height = 120
    $WaitForm.Visible = $True
    $WaitForm.Update()
    sleep -s 5
    #Hide popup
    $WaitForm.Close()
    
    }

    I have tried to debug but cannot find a reason.  By the way its from Windows 7 and firewall is off.

    Tuesday, January 30, 2018 12:38 PM

Answers

  • I fixed it.  The version of powershell on win7 needed to be upgraded
    • Marked as answer by CRGTech Tuesday, January 30, 2018 2:31 PM
    Tuesday, January 30, 2018 2:31 PM

All replies

  • Hi,

    Are you providing the right credentials in $mycreds?

    Tuesday, January 30, 2018 12:48 PM
  • Hi,

    Yes I tried this line by line in the console and it produces the correct output

    Tuesday, January 30, 2018 1:08 PM
  • So far I see that it works on server 2012 but not Windows 7
    Tuesday, January 30, 2018 2:04 PM
  • I fixed it.  The version of powershell on win7 needed to be upgraded
    • Marked as answer by CRGTech Tuesday, January 30, 2018 2:31 PM
    Tuesday, January 30, 2018 2:31 PM