Powershell Taschenrechner Programm Fehlerausgabe sonderzeichen?

Hallo Leute ich hab hier ein Skript für einen Taschenrechner und müsste hier nur die Funktion einbauen das er mir bei der Eingabe von Sonderzeichen eine ordentliche Fehlerausgabe gibt.
Dies hier ist soweit der Code:

Write-Host "Geben Sie zwei Zahlen ein" -ForegroundColor Red

Write-Host "Wählen Sie eine der vier möglichen Rechenoperationen aus:" -ForegroundColor Green

Write-Host "1: Zahl1 : Zahl2 = Ergebnis"

Write-Host "2: Zahl1 + Zahl2 = Ergebnis"

Write-Host "3: Zahl1 - Zahl2 = Ergebnis"

Write-Host "4: Zahl1 * Zahl2 = Ergebnis"

$Zahl1 = Read-Host "Bitte geben Sie die erste Zahl ein" 

$Zahl2 = Read-Host "Bitte geben Sie die zweite Zahl ein"

[int]$Eingabe = Read-Host "Wählen Sie eine Rechenoperation"

$Zahl1 = $Zahl1.Replace(",",".")

$Zahl2 = $Zahl2.Replace(",",".")

$Zahl1 = [double] $Zahl1

$Zahl2 = [double] $Zahl2

#Zulässige Rechenoperationen definiert

switch ($Eingabe) {

1 {$Ergebnis = $Zahl1 / $Zahl2}

2 {$Ergebnis = $Zahl1 + $Zahl2}

3 {$Ergebnis = $Zahl1 - $Zahl2}

4 {$Ergebnis = $Zahl1 * $Zahl2}

}

#Fehlerausgabe bei Division durch 0 und Programmabbruch

if(($Zahl2 -eq 0) -and ($Eingabe -eq 1)){

$antwort = "Es darf nicht durch 0 geteilt werden";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ungültige Eingabe"); break 

}

#Eingabe Rechenoperation darf nicht kleiner 1 und größer 4 sein.

if(($Eingabe -lt 1) -or ($Eingabe -gt 4) -or ($Eingabe -gt 10)){

$antwort = "Die Eingabe liegt nicht im Wertebereich 1-4";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ungültige Eingabe"); break

}

#stimmt die Eingabe mit dem Muster überein, so erfolgt die Berechnung und Ausgabe des Ergebnisses

else{

if($Eingabe -eq 1){

$antwort = "      <" + $Zahl1 + "> : <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A durch B");

   }

if($Eingabe -eq 2){

$antwort = "      <" + $Zahl1 + "> + <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A plus B");

if($Eingabe -eq 3){

$antwort = "      <" + $Zahl1 + "> - <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A minus B");

}

if($Eingabe -eq 4){

$antwort = "      <" + $Zahl1 + "> * <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A mal B");

}

}

Kann mir da jemand weiterhelfen ohne meinen Code komplett zu verändern?

Computer, skript, Taschenrechner, PowerShell, Powershell ISE
Wie kann ich ein PowerShell-Skript mit dem X-Button beenden?

Ich habe eine MessageBox und möchte das Skript beenden, sobald X gedrückt wird.

Kann ich eine Variable hochzählen, wenn ein anderer Button gedrückt wird? Eine Variable, die verhindert, dass mein Skript beendet wird? Mit onClick oder so?

$version = "xy"
Add-Type -AssemblyName System.Windows.Forms

[System.Windows.Forms.Application]::EnableVisualStyles()

$START = New-Object system.Windows.Forms.Form
$START.ClientSize = '400,282'
$START.text = $version
$START.TopMost = $false
$Label1a = New-Object system.Windows.Forms.Label
$Label1a.text = "Inhaltt:"
$Label1a.AutoSize = $true
#$Label1a.width = 25
#$Label1a.height = 10
$Label1a.location = New-Object System.Drawing.Point(9, 24)
$Label1a.Font = 'Microsoft Sans Serif,10'
$Button1a = New-Object system.Windows.Forms.Button
$Button1a.text = "OK"
$Button1a.width = 381
$Button1a.height = 30
$Button1a.location = New-Object System.Drawing.Point(9, 243)
$Button1a.Font = 'Microsoft Sans Serif,10'
$Button1a.add_Click({$START.close()}) #MessageBox wird geschlossen
$TextBox1a = New-Object system.Windows.Forms.TextBox
#$TextBox1a.multiline = $false
$TextBox1a.text = "Inhalt"
$TextBox1a.width = 55
$TextBox1a.height = 20
$TextBox1a.location = New-Object System.Drawing.Point(9, 45)
$TextBox1a.Font = 'Microsoft Sans Serif,10'
$TextBox2a = New-Object system.Windows.Forms.TextBox
#$TextBox2.multiline = $false
$TextBox2a.text = "Inhalt"
$TextBox2a.width = 381
$TextBox2a.height = 20
$TextBox2a.location = New-Object System.Drawing.Point(9, 119)
$TextBox2a.Font = 'Microsoft Sans Serif,10,style=Italic'
$Label2a = New-Object system.Windows.Forms.Label
$Label2a.text = "Inhalt:" #$inputpath #Variable muss noch definiert werden
$Label2a.AutoSize = $true
#$Label2a.width = 25
#$Label2a.height = 10
$Label2a.location = New-Object System.Drawing.Point(9, 98)
$Label2a.Font = 'Microsoft Sans Serif,10'
$Label3a = New-Object system.Windows.Forms.Label
$Label3a.text = "Inhalt:" #$outputpath
$Label3a.AutoSize = $true
#$Label3a.width = 25
#$Label3a.height = 10
$Label3a.location = New-Object System.Drawing.Point(9, 172)
$Label3a.Font = 'Microsoft Sans Serif,10'
$TextBox3a = New-Object system.Windows.Forms.TextBox
#$TextBox3a.multiline = $false
$TextBox3a.text = "Inhalt"
$TextBox3a.width = 381
$TextBox3a.height = 20
$TextBox3a.location = New-Object System.Drawing.Point(9, 192)
$TextBox3a.Font = 'Microsoft Sans Serif,10,style=Italic'
$START.controls.AddRange(@($Label1a, $Button1a, $TextBox1a, $TextBox2a, $Label2a, $Label3a, $TextBox3a, $Label1ab))

[void]$START.ShowDialog()
Computer, Windows, programmieren, Code, Script, PowerShell, Powershell ISE
PowerShell: "Es wurde kein Positionsparameter gefunden, der das Argument "+" akzeptiert." Wie löse ich das?

Hi

Es geht um Reports... Programmiert wurde es mit PowerShell ISE

Hier der Fehler:

Rename-Item : Es wurde kein Positionsparameter gefunden, der das    Argument  "+" akzeptiert.
In Zeile:34 Zeichen:1
+ rename-item "c:\Reporting\Report_Telephone_" + $todaydate[0] +'-' + $todaydate[1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Rename-Item], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand

hier mein Code:

#today's date (year-month-day)
$todaydate = Get-Date -Format yyyy-MM-dd

#arrays  (today => systemtime)
$todaydate = $todaydate.Split('-')
$todaydate[0] #year
$todaydate[1] #month
$todaydate[2] #day

#arrays yesterday (systemtime - one day)
$yesterdaysdate = Get-Date((Get-Date).AddDays(-1)) -Format yyyy-MM-dd
$yesterdaysdate = $yesterdaysdate.Split('-')
$yesterdaysdate[0] #year
$yesterdaysdate[1] #month
$yesterdaysdate[2] #day

#arrays yesterday (systemtime - one day)
$lastmonth = Get-Date((Get-Date).AddMonths(-1)) -Format yyyy-MM-dd
$lastmonth = $lastmonth.Split('-')
$lastmonth[0] #year
$lastmonth[1] #month
$lastmonth[2] #day


#Example 1:  Filename "Report_Telephone_yyyy-mm" => in this case "Report_Telephone_2016-12"
#it renames the file -> minus one month, so the name must be "Report_Telephone_2016-11"
$filename='Report_Telephone_'+ $lastmonth[0]+'-'+ $lastmonth[1] + '.xlsx'
$filemonth = [int][regex]::Match($filename, '\w+_\d+_(\d+)').Groups[1].Value
$filemonth = "{0:D2}" -f ($filemonth - 1)

write-host $filename
rename-item "c:\Reporting\Report_Telephone_" + $todaydate[0] +'-' + $todaydate[1] + ".xlsx" -NewName $filename

$sourcepath='C:\Reporting\'+ $filename
write-host $sourcepath
$destinationpath='C:\Reporting\'+ $lastmonth[0]+'\'+ $lastmonth[1]
write-host $destinationpath
if(test-path $destinationpath)
{

} 
else 
  {
     mkdir $destinationpath
  }
move-item -path $sourcepath -destination $destinationpath

Hat einer ne Idee, wie ich das lösen könnte? Thx im vorraus :3

PC, Computer, Windows, IT, programmieren, Informatik, PS, Report, Script, PowerShell, Powershell ISE

Meistgelesene Fragen zum Thema Powershell ISE