Dan P
Dan P

Reputation: 1999

Custom Properties on PowerShell 3.0

I'm very new to power shell but what I'm I doing wrong.

Here is my script

Write-Host "PowerShell Version = " ([string]$psversiontable.psversion) 
for($i=1; $i -le 3; $i++)    
{
    $failedObject = @{'IPAddress'='192.168.0.1';
                'Username'='someusername';
        'FailedAttempts'= 0;
                }

    $failedObject.FailedAttempts = 10

    Write-Host $failedObject.IPAddress
    Write-Host $failedObject.Username    
    Write-Host $faileObject.FailedAttempts
}

Here is the output

PS C:\Users\Administrator> C:\PSScripts\pstest2.ps1
PowerShell Version =  3.0
192.168.0.1
someusername

192.168.0.1
someusername

192.168.0.1
someusername

I think I am having issue with adding custom properties to my object but not sure what I am doing wrong. It appears to only happen for the FailedAttempts property and not for the Username or the IPAdress property.

Is this because it is an int property. What am I doing wrong? Eventually I will want to find an object based on IPAddress and Username and increment FailedAttempts by 1 or add object to an existing array based on IPAddress and Username...do you have easy code for that?

I guess my main question for now is why is the FailedAttempts not showing up in the Write-Host?

Upvotes: 0

Views: 125

Answers (1)

Andy Arismendi
Andy Arismendi

Reputation: 52577

You have a typo on this line:

Write-Host $faileObject.FailedAttempts

Look closely.

Upvotes: 2

Related Questions