So?

What does $all_Tapes display before the "if" statement?

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On 
Behalf Of Daniel Chenault
Sent: Monday, April 6, 2015 6:18 PM
To: powershell@lists.myitforum.com
Subject: RE: [powershell] reference elements

Changed it (and that may indeed be a problem) but still no go.

Immediately before the IF line I put:
$tape.label
so the whole catalog should print out, one line at a time, regardless of the IF 
conditions.

Blank screen. Nothing at all. I've already verified the $all_tapes var does 
indeed have the intended information (i.e. the full catalog).
________________________________
From: mich...@smithcons.com<mailto:mich...@smithcons.com>
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: RE: [powershell] reference elements
Date: Mon, 6 Apr 2015 22:06:46 +0000
PowerShell recognizes and respects typical operator precedence.

[N.B. - I always quote my subexpressions - force of habit from FORTRAN, 30+ 
years ago.]

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Liu, Gavin
Sent: Monday, April 6, 2015 5:44 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: RE: [powershell] reference elements

Try changing your if logic to

if (($tape.label -like "*monthly*") -and ($tape.location -ne "offline"))

The way it reads now, I wouldn't be surprised if it's just confused on what to 
evaluate.

Gavin

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Daniel Chenault
Sent: Monday, April 6, 2015 1:54 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: RE: [powershell] reference elements

I did that for debugging since I wasn't sure I had the concatente done right; 
simplified it to take that out just to get the IF logic right. The output file 
should have one element in it. It has none.

I put a statement in the IF block of "$tape.label" and it prints "$tape.label" 
to the screen rather than a slot # for each element it encounters in the 
$all_tapes var.

This has been a bugaboo of mine with powershell; trying to extract data from 
attributes. Every time I think I have it I encounter a situation where it 
doesn't work.
________________________________
From: mich...@smithcons.com<mailto:mich...@smithcons.com>
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: RE: [powershell] reference elements
Date: Mon, 6 Apr 2015 20:23:33 +0000
..and get rid of the "| ft -autosize" at the end of the $all_tapes statement.

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Crawford, Scott
Sent: Monday, April 6, 2015 4:19 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: RE: [powershell] reference elements

Try [array]$eject_tapes += $tape.location

You're reassigning $eject_tapes every time through the loop and not appending a 
value.

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Daniel Chenault
Sent: Monday, April 6, 2015 3:06 PM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>
Subject: [powershell] reference elements

I thought I had this right, but apparently not.

It's my understanding that when selecting multiple attributes of a cmdlet's 
output it creates an array. Yet it's not working.

$eject_tapes = $null
$all_tapes = Get-ProtectionGroup -DPMServer SD-SCDPM-01 | Get-Tape | Select 
Label, Barcode, Location | Sort-Object Label | ft -autosize
foreach ($tape in $all_tapes)
{
    if ($tape.label -like "*monthly*" -and $tape.location -ne "offline")
    {
        $eject_tapes = $tape.location
    }

}
out-file -filepath "c:\users\danielcadmin\documents\tapes.txt" -inputobject 
$eject_tapes

Output file is empty and shouldn't be. Doing this manually I see it's not 
picking up that I want the element. I've also tried $tape.[0] without joy. This 
is part of a larger project BTW.

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

Reply via email to