?
Solved

Powershell - Read hashtable from file

Posted on 2013-05-19
1
Medium Priority
?
1,171 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:
Meir Rivkin earned 2000 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

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

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

How to effectively resolve the number one email related issue received by helpdesks.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

809 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