Solved

Powershell list evaluation

Posted on 2014-11-19
2
136 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
[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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

733 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