Solved

Powershell list evaluation

Posted on 2014-11-19
2
139 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 70

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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)

691 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