Share via

How us Switch

a a 81 Reputation points
2023-10-19T16:26:20.0133333+00:00

Hello Sir !

Pls, How render the result after I have us the switch parameter?

All works perfect! but the last have en error, but i don't see him ...


cls

""

$xval1 = (Get-Date).dayofyear

$xval1 = $xval1 | % {($_.Length)}

switch ($xval1)

{

1 {$XDay_of_Earth_Year = "   " + (Get-Date).dayofyear + "."}

2 {$XDay_of_Earth_Year = "    " + (Get-Date).dayofyear + "."}

3 {$XDay_of_Earth_Year = "     " + (Get-Date).dayofyear + "."}

}

$XDay_of_Earth_Year

""

$xval2 = ((Get-Date).dayofyear) - (([datetime]'12/31' - [datetime]'1/1') | % days)

switch ($xval2.tostring().Length)

{

1 {$xday_left_year_earth = "   " + $xval2 + ". | "}

2 {$xday_left_year_earth = "    " + $xval2 + ". | "}

3 {$xday_left_year_earth = "     " + $xval2 + ". | "}

4 {$xday_left_year_earth = "      " + $xval2 + ". | "}

}

$Xday_left_year_earth

""

$Xvaleur2 = "4"

switch ($Xvaleur2.Length)

{

1 {$xday_month_luna_val = "-  " + $Xvaleur2 + ". "}

2 {$xday_month_luna_val = "-   " + $Xvaleur2 + ". "}

}

$xday_month_luna_val

""

$Xvaleur3 = "8"

switch ($Xvaleur3.Length)

{

1 {$Xluna_month_val = "-  " + $Xvaleur3 + ". "}

2 {$Xluna_month_val = "-   " + $Xvaleur3 + ". "}

}

$Xluna_month_val

""

"==================================================="

$Xdate_day = Get-Date -Format %d

""

$Xdate_day.Length # " now, 2 length is okay !!!!!"

switch ($Xdat)

{

 1 {$Xday_earth = " -    " + [string]$Xdate_day } # le 19

 2 {$Xday_earth = " -     " + [string]$Xdate_day }

}

""

$Xday_earth

""" day_earth is not match """

"==================================================="

""

clear-variable X* -scope global -Force


The result is:

   292.

     -72. | 

-  4. 

-  8. 

===================================================

2

" day_earth is not match "
===================================================

rapport-luna-earth.txt

Thank for your Help

Arnold

Windows for business | Windows Server | User experience | PowerShell

2 answers

Sort by: Most helpful
  1. a a 81 Reputation points
    2023-10-19T19:15:41.2133333+00:00

    Good evening sir! I read your letter on my cell phone. We talked about the “switsch”. I believed that all problems were solved now. But unfortunately I don't get an answer to the last script. (last line).

    "================================================= =="

    $Xdate_day = Get-Date format %d
    $Xdate_day.Length # " now, 2 length is okay !!!!!"
    switch ($Xdate_day)
    {
          1 {$Xday_earth = " - " + [string]$Xdate_day } # le 19
          2 {$Xday_earth = " - " + [string]$Xdate_day }
    }
    $Xday_earth
    """ day_earth is not match """
    

    "================================================= =="

    clear-variable X* -scope global -Force
    

    I don't get any error message. So what should I do?

    I m so sorry

    Thanks

    Arnold

    
    

    Was this answer helpful?

    0 comments No comments

  2. a a 81 Reputation points
    2023-10-19T17:11:54.48+00:00
    cls
    
    ""
    $xval1 =  (Get-Date).dayofyear
    $xval1 = $xval1 | % {($_.Length)}
    switch ($xval1)
    {
        1 {$XDay_of_Earth_Year = "   " + (Get-Date).dayofyear + "."}
        2 {$XDay_of_Earth_Year = "    " + (Get-Date).dayofyear + "."}
        3 {$XDay_of_Earth_Year = "     " + (Get-Date).dayofyear + "."}
    }
    $XDay_of_Earth_Year
    ""
    $xval2 = ((Get-Date).dayofyear) - (([datetime]'12/31' - [datetime]'1/1') | % days)
    switch ($xval2.tostring().Length)
    {
        1 {$xday_left_year_earth = "   " + $xval2 + ". | "}
        2 {$xday_left_year_earth = "    " + $xval2 + ". | "}
        3 {$xday_left_year_earth = "     " + $xval2 + ". | "}
        4 {$xday_left_year_earth = "      " + $xval2 + ". | "}
    }
    $Xday_left_year_earth
    ""
    $Xvaleur2 = "4"
    switch ($Xvaleur2.Length)
    {
        1 {$xday_month_luna_val = "-  " + $Xvaleur2 + ". "}
        2 {$xday_month_luna_val = "-   " + $Xvaleur2 + ". "}
    }
    $xday_month_luna_val
    ""
    $Xvaleur3 = "8"
    switch ($Xvaleur3.Length)
    {
        1 {$Xluna_month_val = "-  " + $Xvaleur3 + ". "}
        2 {$Xluna_month_val = "-   " + $Xvaleur3 + ". "}
    }
    $Xluna_month_val
    ""
    
    "==================================================="
    $Xdate_day = Get-Date -Format %d
    ""
    $Xdate_day.Length # " now, 2 length is okay !!!!!"
    switch ($Xdat_day)
    {
         1 {$Xday_earth = " -    " + [string]$Xdate_day } # le 19
         2 {$Xday_earth = " -     " + [string]$Xdate_day }
    }
    ""
    $Xday_earth
    """ day_earth is not match """
    "==================================================="
    ""
     clear-variable X* -scope global -Force
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.