Good morning
I am just starting out on powershell and have a short script that outputs a countdown timer. The script runs perfectly in powershell_ise using F5, however when run from command line produces errors. After much searching I cannot find anything relevant to this error.
Script and error produced as follows:
SCRIPT
$delay = 5
$a=Get-Date -Format "dd/MM/yyyy"
[system.Media.SystemSounds]::Asterisk.Play()
$Counter_Form = New-Object System.Windows.Forms.Form
$Counter_Form.Text = "Archive logs"
$Counter_Form.Width = 600
$Counter_Form.Height = 200
$Counter_Form.StartPosition = "CenterScreen"
$Counter_Form.BackColor = "#ffffff"
$Counter_Label = New-Object System.Windows.Forms.Label
$Counter_Label.AutoSize = $true
$Counter_Label.ForeColor = "Black"
$normalfont = New-Object System.Drawing.Font("Segoe UI",10)
$Counter_Label.Font = $normalfont
$Counter_Label.Left = 50
$Counter_Label.Top = 30
$Counter_Form.Controls.Add($Counter_Label)
while ($delay -ge 1)
{
$Counter_Form.Show()
$Counter_Label.Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program will terminate in $($delay) seconds"
start-sleep 1
$delay -= 1
}
$Counter_Form.Close()
OUTPUT
Microsoft Windows [Version 6.0.6002]
Copyright © 2006 Microsoft Corporation. All rights reserved.
C:\Users\Richard>powershell c:\countdown.ps1
New-Object : Cannot find type [system.Windows.Forms.Form]: make sure the assembly containing this type is loaded.
At C:\countdown.ps1:4 char:27
+ $Counter_Form = New-Object <<<< System.Windows.Forms.Form
+ CategoryInfo : InvalidType: ( [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
Property 'Text' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:5 char:15
+ $Counter_Form. <<<< Text = "Archive logs"
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Width' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:6 char:15
+ $Counter_Form. <<<< Width = 600
+ CategoryInfo : InvalidOperation: (Width:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Height' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:7 char:15
+ $Counter_Form. <<<< Height = 200
+ CategoryInfo : InvalidOperation: (Height:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'StartPosition' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:8 char:15
+ $Counter_Form. <<<< StartPosition = "CenterScreen"
+ CategoryInfo : InvalidOperation: (StartPosition:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'BackColor' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:9 char:15
+ $Counter_Form. <<<< BackColor = "#ffffff"
+ CategoryInfo : InvalidOperation: (BackColor:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
New-Object : Cannot find type [system.Windows.Forms.Label]: make sure the assembly containing this type is loaded.
At C:\countdown.ps1:10 char:28
+ $Counter_Label = New-Object <<<< System.Windows.Forms.Label
+ CategoryInfo : InvalidType: ( [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
Property 'AutoSize' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:11 char:16
+ $Counter_Label. <<<< AutoSize = $true
+ CategoryInfo : InvalidOperation: (AutoSize:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'ForeColor' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:12 char:16
+ $Counter_Label. <<<< ForeColor = "Black"
+ CategoryInfo : InvalidOperation: (ForeColor:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
New-Object : Cannot find type [system.Drawing.Font]: make sure the assembly containing this type is loaded.
At C:\countdown.ps1:13 char:25
+ $normalfont = New-Object <<<< System.Drawing.Font("Segoe UI",10)
+ CategoryInfo : InvalidType: ( [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
Property 'Font' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:14 char:16
+ $Counter_Label. <<<< Font = $normalfont
+ CategoryInfo : InvalidOperation: (Font:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Left' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:15 char:16
+ $Counter_Label. <<<< Left = 50
+ CategoryInfo : InvalidOperation: (Left:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Top' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:16 char:16
+ $Counter_Label. <<<< Top = 30
+ CategoryInfo : InvalidOperation: (Top:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:17 char:27
+ $Counter_Form.Controls.Add <<<< ($Counter_Label)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:20 char:21
+ $Counter_Form.Show <<<< ()
+ CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Property 'Text' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:21 char:18
+ $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program
will terminate in $($delay) seconds"
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:20 char:21
+ $Counter_Form.Show <<<< ()
+ CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Property 'Text' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:21 char:18
+ $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program
will terminate in $($delay) seconds"
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:20 char:21
+ $Counter_Form.Show <<<< ()
+ CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Property 'Text' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:21 char:18
+ $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program
will terminate in $($delay) seconds"
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:20 char:21
+ $Counter_Form.Show <<<< ()
+ CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Property 'Text' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:21 char:18
+ $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program
will terminate in $($delay) seconds"
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:20 char:21
+ $Counter_Form.Show <<<< ()
+ CategoryInfo : InvalidOperation: (Show:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Property 'Text' cannot be found on this object; make sure it exists and is settable.
At C:\countdown.ps1:21 char:18
+ $Counter_Label. <<<< Text = " LOGS CANNOT BE ARCHIVED UNTIL FIRST DAY OF MONTH`n`nTodays date is: $a - Program
will terminate in $($delay) seconds"
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\countdown.ps1:26 char:20
+ $Counter_Form.Close <<<< ()
+ CategoryInfo : InvalidOperation: (Close:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
C:\Users\Richard>
I am guessing there is a simple explanation to this and I am misunderstanding the application somewhere, but as I said after much googling have been unable to find anything relevant so any assistance would be greatly received.
For your info OS is Vista SP2 and Powershell is v1.0.
Many thanks