Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 936479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:19:17+00:00 2026-05-15T21:19:17+00:00

I have a function accepting an enum value as parameter. As an example, consider

  • 0

I have a function accepting an enum value as parameter. As an example, consider something like:

(PS) > function IsItFriday([System.DayOfWeek] $dayOfWeek) { 
    if($dayOfWeek -eq [System.DayOfWeek]::Friday) {
        "yes"
    } else {
        "no"
    } 
}

Now, if I invoke it like this, everything is fine:

(PS) > $m = [System.DayOfWeek]::Monday
(PS) > IsItFriday $m
no

But if I call the function passing directly the enum value, I get a rather cryptic error:

(PS) > IsItFriday [System.DayOfWeek]::Monday
IsItFriday : Cannot convert value "[System.DayOfWeek]::Monday" to type "System.DayOfWeek" 
due to invalid enumeration values. Specify one of the following enumeration values and 
try again. The possible enumeration values are "Sunday, Monday, Tuesday, Wednesday, 
Thursday, Friday, Saturday".
At line:1 char:11
+ IsItFriday  <<<< [System.DayOfWeek]::Monday

What’s the difference between initializing a variable with the enum value and passing the enum value directly?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:19:17+00:00Added an answer on May 15, 2026 at 9:19 pm

    Yes, that is a rather confusing error message. I think you would understand better with an example:

    Get-ChildItem -Path C:\
    

    Notice there are no quotes around C:\ because, one, it implcitly gets converted to a string, and two, it is not necessary to enclose a path which does not contain spaces when you pass the path as a parameter to some callee.

    So lets go back to your function, and change it slightly:

    function IsItFriday($dayOfWeek) 
    {
        $dayOfWeek.GetType()
    
        if ($dayOfWeek -eq [System.DayOfWeek]::Friday) 
        {
            "yes"
        } 
        else 
        {
            "no"
        }
    }
    
    IsItFriday [System.DayOkWeek]::Monday
    

    …and the output:

    IsPublic IsSerial Name                                     BaseType                                                                                        
    -------- -------- ----                                     --------                                                                                        
    True     True     String                                   System.Object                                                                                   
    no
    

    See what happened there? PowerShell thinks you are passing in a string instead of an enumeration value, so that’s why you get Cannot convert value "[System.DayOfWeek]::Monday" because that is the literal string that gets passed in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
I have a Python function accepting several string arguments def foo(a, b, c): and
I have some xml that I manually construct in a function that is something
I have a function accepting 2 Ints n, x, and calculates floor (log n/log
I have a function accepting requests from the network. Most of the time, the
I have a function that is accepting the date and time, and number of
I have function LoadTempMovieList(), and need to load movies from sessionStorage. But it seems
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.