Solved

Powershell - Read hashtable from file

Posted on 2013-05-19
1
999 Views
Last Modified: 2013-05-24
hi all,

i like to read an hash table from an external file. The file called company.txt looks like
follows.


  "contoso" = 'contoso.com'
  "contoso1" = 'contoso1.com'
 
I tried different things but the file not reading correctly.

Who can help here?
mandy
0
Comment
Question by:Mandy_
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39180127
cls
$data = @()
gc c:\temp\hash.txt | %{
	$tokens = $_ -split '[''="]' | where{$_.Trim() -ne ''}
	$item = New-Object System.Object
	$item | Add-Member -type NoteProperty -name Key -value $tokens[0]
	$item | Add-Member -type NoteProperty -name Value -value $tokens[1]
	$data +=  $item
}

$data

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question