Is this a decent analog for your script? $List = $null $Files = Get-ChildItem C:\ foreach ($File in $Files) { if ($File.Name -like "program*") { [array]$List += $File.Name } } Out-File -FilePath "C:\files.txt" -InputObject $List
When I run this, c:\files.txt contains: ----snip---- Program Files Program Files (x86) ----snip---- It seems the only difference is the extra stuff you're doing on the pipeline during the assignment of $all_tapes. Are you sure that $tape.label and $tape.location are strings? I don't have tapes on my DPM server so I can't test it, but what do you get with (Get-ProtectionGroup -DPMServer SD-SCDPM-01 | Get-Tape | Select Label, Barcode, Location) | Get-Member Do you see Label, Barcode, and Location as NoteProperty - Definition System.String? From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Daniel Chenault Sent: Monday, April 6, 2015 3:54 PM To: 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