[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Powershell

Posted on 2011-09-07
3
Medium Priority
?
557 Views
Last Modified: 2012-05-12
I have a document.txt file that has over 100 lines in it. The following information is an example of how the information is setup in the file.
ComputerName=Person
LastLogin=Date
ComputerName=Person
LastLogin=Date

What I'm trying to achive is the following..a comma delimitied file but with the following output

Person,Date
Person,Date
Person,Date

I'm in the process of trying to write this code in powershell.

Currently I'm able to output a file that is similar to the example below, but I'm trying to matchh up the Person and the date and remove ComputerName and LastLogin information.  Below is an example of what I can currently output:

ComputerName,Person
LastLogin,Date
0
Comment
Question by:wnbtechnology
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 500 total points
ID: 36499520
Get-Content YourFile.txt | % {
  $value = $_.split("=")[1]
  if ($_.StartsWith("ComputerName=")) {
    $computer = $value
  } else {
    Write-Output ($computer + ', ' + $value)
  }
}

Open in new window

You can redirect the output to a file, of course.
0
 
LVL 10

Expert Comment

by:wls3
ID: 36502205
This can solve the issue of getting paired lines:
for($i = 0; $i -lt $file.Length; $i++) {
  "Lines: $i - $($i+1): " + $file[$i,$i+2]; 
  $i++
}

Open in new window

Using a file that contains this text:
param(
        $valuepassedasargument
)

# Display the argument
Write-Output "Param: $valuepassedasargument";

# Display the value by accessing the $args collection
Write-Output "`$args: $args";

# Display something just as a sanity check
Write-Output "Sanity check: Something";

# Wait for input to pause processing
read-host;

Open in new window

I get this output:
Lines: 0 - 1: param( param( )
Lines: 2 - 3: ) ) )
Lines: 4 - 5: # Display the argument # Display the argument )
Lines: 6 - 7:   )
Lines: 8 - 9: Write-Output "`$args: $args"; Write-Output "`$args: $args"; )
Lines: 10 - 11: # Display something just as a sanity check # Display something just as a sanity check )
Lines: 12 - 13:   )
Lines: 14 - 15: read-host; read-host; )

Open in new window

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 36502305
@wls:  Wrong thread???
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrā€¦

656 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