You might want to ask your teacher for some 1 on 1 tutoring. Or review these sites.
https://learn.microsoft.com/en-us/powershell/scripting/learn/more-powershell-learning?view=powershell-5.1
https://www.guru99.com/powershell-tutorial.html
But I am getting the error.
What error are you getting? You misspelled "write-host", you have "wite".
Need PowerShell script to check the variable
Which variable? Demostring? Value? Desc? It is not clear what your script is doing with these variables.
Let's start with the first few lines of your script. .
param(
[string]$DemoString,
[string]$value
)
That code says that your script accepts 2 positional input parameters. Save this as demo.ps1 and test it.
param(
[string]$DemoString,
[string]$value
)
"Here are the parameters that this script was invoked with."
"Demostring: {0}" -f $DemoString | Write-Host
"value : {0}" -f $value | Write-Host
Test it like this.
PS C:\Temp> .\demo.ps1 xxx aaa
Here are the parameters that this script was invoked with.
Demostring: xxx
value : aaa
But in your code you immediately prompt the console user and overwrite the passed values. That doesn't make sense.
$DemoString = Read-Host "Enter:"
$value = Read-host "Enter value :"
From a learning point of view, it would make more sense to teach how to validate input data. like this.
param(
[string]$DemoString,
[string]$value
)
$ValidData = $true # the tests will set this to false if we find bad data.
if($DemoString -eq $null)
{
Write-Host "Demostring was null. "
$ValidData = $false
}
if($DemoString -eq '')
{
Write-Host "Demostring was blank. "
$ValidData = $false
}
if($value -eq $null)
{
Write-Host "Value was null. "
$ValidData = $false
}
if($value -eq '')
{
Write-Host "Value was blank. "
$ValidData = $false
}
if ($ValidData)
{
Write-Host "Input data is valid."
}
else
{
Write-Host "Please rerun this script and pass 2 valid parameters."
return
}
Write-Host "Now process the data."
"Demostring: {0}" -f $DemoString | Write-Host
"value : {0}" -f $value | Write-Host