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 7160761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:27:04+00:00 2026-05-28T13:27:04+00:00

I am creating a new object for export values to CSV: New-Object -TypeName PSObject

  • 0

I am creating a new object for export values to CSV:

New-Object -TypeName PSObject -Property @{
            host_name = ($server.name).ToLower()
            address = $IPAddress
            host_is_collector = "no"
            host-preset = "windows-server"
        } | Select-Object host_name,address,host-preset | Export-Csv -Path $nConf_import_host_file

The problem is that one of the lines contains a dash (host-preset). I would ofcourse simply change it to an underscore, but my CSV needs this value to be a dash. I could also do a -replace on the entire csv after it has been created but that seems dirty.
Is there a way I can use dash here?

My error msg is:

Missing '=' operator after key in hash literal.
At Z:\Scripts\Testscripts\ScanServers_and_check_nagiosV7.ps1:336 char:16
+                 host-preset <<<<  = "windows-server"
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEqualsInHashLiteral
  • 1 1 Answer
  • 0 Views
  • 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-28T13:27:05+00:00Added an answer on May 28, 2026 at 1:27 pm

    You simply need to treat the host-preset property name as a string by enclosing it in quotes:

    New-Object -TypeName PSObject -Property @{ "host-preset" = "windows-server" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After creating a new object (Foo), I set the key (BarId) for an EntityRef
When creating a new entity object that has a foreign key value I need
i am creating a Geocoder object like. Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); here
I am creating a new object in a Powershell script, or actually an object
When creating a new object in PHP, I get the following error message: Fatal
I'm creating a new object like this: TestObject->new(@array1, @array2) My new method looks like
I have an application where I'm creating a new object via a new action.
Okay, so the book says: when creating a new object, you can pass a
I want to program the basic CRUD operations of caching (creating new object ,
even after creating new object of unmarshaller every time, threads are getting blocked Please

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.