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
Solved

Powershell list evaluation

Posted on 2014-11-19
2
135 Views
Last Modified: 2014-11-19
I'm working on a PowerShell script that queries our BackupExec database for the most recent completed jobs with "TM2ID" in the name and then uses the data from that query to send a status update through another script. Current code looks like this:

get-bejobhistory -fromstarttime (get-date).addminutes(-60) | where-object {$_.Name -like '*TM2ID*'} 

Open in new window


and the result I get is this:

Name                            JobStatus JobType StartTime             EndTime              
----                            --------- ------- ---------             -------              
Backup 00283-Full (TM2ID:33)    Succeeded Backup  11/19/2014 9:02:54 AM 11/19/2014 9:04:22 AM
Backup 00284-Full (TM2ID:133)   Canceled  Backup  11/19/2014 9:08:22 AM 11/19/2014 9:09:49 AM
Backup 00285-Full (TM2ID:4233)  Failed    Backup  11/19/2014 9:12:36 AM 11/19/2014 9:14:04 AM

Open in new window


What I need to do with each item found is put the number following "TM2ID:" into one variable and the JobStatus into another variable, and then do stuff with those variables (I think I've got that part figured out).
0
Comment
Question by:PaulRKrueger
2 Comments
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 200 total points
ID: 40452839
JobStatus is already a property of the result, so no work needed here.
The TM2 ID requires parsing or splitting. E.g.
get-bejobhistory -fromstarttime (get-date).addminutes(-60) |
   where-object {$_.Name -like '*TM2ID*'}  |
   select *, @{n='TM2ID'; e={ ($_.Name -split ':|\)')[1] }}

Open in new window

0
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 300 total points
ID: 40453259
$history = get-bejobhistory -fromstarttime (get-date).addminutes(-60) | where-object {$_.Name -like '*TM2ID*'}
$history | foreach{
$number = $_.Name.split(":")[1].trim(")")
$status = $_.Jobstatus
...}

$number and $status are the two variables and you can play around them in the rest of your script. As its a list of items you can run through foreach loop and enclose your line of script within the loop to use those variables.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

840 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