I'm starting to make some scripts in PowerShell but I have a problem.
I want to count the number of characters that someone introduce by keyboard. I'm trying this:
write-host $FC
$numcar = $FC.CountBut it always returns 1.
Can someone help me?
1 Answer
Change your code to the following:
$FC = Read-Host -Prompt "Please enter some characters"
$numcar = $FC.lengthYou need to use the Read-Host command in order to get input from the keyboard. So this code sets the $FC variable to the data inputted from Read-Host and then the variable $numcar is set to the amount of characters entered, or 'length'. You got this confused with 'Count'.