wsman:\localhost\Client\TrustedHosts How to add a bunch of strings/ComputerNames

Welcome Forums General PowerShell Q&A wsman:\localhost\Client\TrustedHosts How to add a bunch of strings/ComputerNames

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
3 years, 2 months ago.

  • Author
    Posts
  • #31648

    Participant
    Points: 0
    Rank: Member

    Hello kind people! Some help would be greatly appreciated for a PS enthusiast and an absolute beginner.

    I am trying to set a bunch of string values/computernames which I imported from a csv file.

    I used this command to have strings:
    "import-csv -path c:\csvfile.csv | select-object computername -expandproperty computrername"

    Know I wolud like to feed that to "Set-Item wsman:\localhost\Client\TrustedHosts -Value" all at once so I can PSRemote to these machines in a workgroup environment which I trust.

    I can't seem to accomplish this.

    "-Value []
    Accept pipeline input? true (ByValue, ByPropertyName)"

    I can't figure it out how to do it. Please advise.

  • #31649

    Participant
    Points: 0
    Rank: Member

    Guess it is because the Value field within WSMAN is expecting the value to be in the format of "computer1,computer2,computer3"

    but from what you say you have a list of computernames like this
    "computer1"
    "computer2"
    "computer3"

    I recon you need for format it properly to a new variable string and then pass the new variable to the set-item command.

    Hope this helps.

  • #31690

    Participant
    Points: 22
    Rank: Member

    Check out Add-TrustedHost, part of my Carbon module. It will put things in the right format for you.

    If you don't want to use the module, here is the source code

  • #31703

    Participant
    Points: 0
    Rank: Member

    you wrote an entire function? thank you for sharing this.

    Thank you very much. This is awesome!

  • #31706

    Participant
    Points: 0
    Rank: Member

    @Aaron

    In fact all I needed is the piece of code in your function where I put my import-csv -path c:\csvfile.csv | select-object computername -expandproperty computrername in a variable and created another variable and used " join ',' " with the first one.

    I fed that to set-item parameter "-value" and it worked. What a rookie thing not to know the "join" operator to join a bunch of imported strings and delimited them with commas.

    Well I didn't konw how to do it and I wanted to use a "oneliner".

    thank you once more.

The topic ‘wsman:\localhost\Client\TrustedHosts How to add a bunch of strings/ComputerNames’ is closed to new replies.