Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

compare variable to object in array

$
0
0

Hello

i am trying to get my script working but i am having some problem.

I have a script that allows me to enter a string in a popup window.

What i am trying to do is to get that string that has been entered into a variable and to compare it to an object from array and if it is equal to it to create a file with matched string.

Here is what i have:

 

$serverLogfolder = (gci "D:\!Joro\Powershell\" | where-object { $_.PSIsContainer} | sort CreationTime -desc | select -f 1 | Foreach-Object { $_.FullName })
 
$Errorfile = ""
#$Dbmodulefile = @(Get-ChildItem (join-path $serverLogFolder $serverLogfile) -Filter *.txt | ForEach-Object{'{0,-20}{1,10}' -f $_.Name,(Get-Content $_).Count })
#$Errorreport_file = @(Get-ChildItem $errorfile -Filter *.txt | ForEach-Object{'{0,-20}{1,10}' -f $_.Name,(Get-Content $_).Count })
$LogfilesAray = @("a.xt", "b.txt", "c.txt")
$ErrorfilesAray = @("a_error.txt", "b_error.txt", "c_error.txt")



[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the information in the space below:"
$objForm.Controls.Add($objLabel)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

$x


    if ( $x  -eq $LogfilesAray[0])
    {
        $errorfile == ErrorfilesAray[0]write-host "True"
    }
}
(Get-Content (join-path $serverLogfolder $serverLogfile) | Where-Object {$_.StartsWith((Get-Date).AddDays(-1).ToString("yyyyMMdd"))}  | select-string -notmatch "Network Error" | out-file "D:\Powershell\errorfiles\"$Errorfile)

 

This is what i am trying but i am getting error:

out-file: cannot validate argument on parameter 'encoding'. The argument "" doesn not belong yo the set "unicode, utf7,utf8,utf32" specified by the ValidateSet attribute.Supply the argument that is in the set

Is it possible to have variable with empty string like: $Errorfile = ""

and to assign it the result after i compare input variable to the array object.

Can any one help me with this :)

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles