Solved

Powershell list evaluation

Posted on 2014-11-19
2
129 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 68

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now