True, this would also work:
Get-ProtectionGroup -DPMServer SD-SCDPM-01 | Get-Tape | Where-Object Label -like "*monthly*" | Where-Object Location -ne "offline" | Export-Csv -Encoding ASCII -Path "c:\users\danielcadmin\documents\tapes.csv" -k From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Crawford, Scott Sent: Monday, April 6, 2015 3:56 PM To: powershell@lists.myitforum.com Subject: RE: [powershell] reference elements Does location need to be expanded? If so, that's missing from the original script. From: listsad...@lists.myitforum.com <mailto:listsad...@lists.myitforum.com> [mailto:listsad...@lists.myitforum.com] On Behalf Of Keith Garner (Hotmail) Sent: Monday, April 6, 2015 5:22 PM To: powershell@lists.myitforum.com <mailto:powershell@lists.myitforum.com> Subject: RE: [powershell] reference elements Embrace the pipeline. Single line: Get-ProtectionGroup -DPMServer SD-SCDPM-01 | Get-Tape | Where-Object Label -like "*monthly*" | Where-Object Location -ne "offline" | Select-Object -ExpandProperty Location | sort | out-file -Encoding ascii "c:\users\danielcadmin\documents\tapes.txt" I do NOT recommending performing "Select label,barcode,location" just to filter out properties, just pass all properties along the pipeline. Additionally, no need to sort so early along the process, wait till the end. 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: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