Make sure $all_tapes is enumerable and not a string. It will be a string if you use the format-table like you were in your original version. You many have already done this, but get rid of the sort-object as well. Since you know there is only one hit, the sort is only taking up excess time and is unnecessary.
Try to display bot $tape and $all_tapes in your foreach to see what each variable holds during each loop iteration, just for debugging. In you if statement, call the out-file operation if you know there will always only be one match for the condition you are looking for, it will be more efficient and you can exit your loop within the if statement as well, being more efficient. Regarding the attributes, it really depends on what the return type is from your Get-ProtectionGroup and Get-Tape. Some objects require extra steps to extract the data. WMI lazy properties are a good example of what I am talking about. You can't just read those values in a standard get-wmiobject call. To make things easier, dump all the attributes of the data returned from each of your commandlets. Get-ProtectionGroup -DPMServer SD-SCDPM-01 | get-member Get-ProtectionGroup -DPMServer SD-SCDPM-01 | Get-Tape | get-member To see what type they are and what methods or properties are available for each returned datetype or object. Once you understand the objects you are working with you will better be able to access any properties/values that are available. You can also just dump all elements of each to see what you have to work with. Get-ProtectionGroup -DPMServer SD-SCDPM-01 | select * Get-ProtectionGroup -DPMServer SD-SCDPM-01 | Get-Tape | select * From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Daniel Chenault Sent: Monday, April 06, 2015 7:11 PM To: powershell@lists.myitforum.com Subject: RE: [powershell] reference elements Compressing as Keith noted worked fine although it gave me some columns I wasn't expecting. And I'm still having trouble extracting data from the attribute which I need later on. I really need a good text that explains how PS holds and references attributes and how to extract them. As I mentioned before this is probably my biggest hang-up with PS and bothering the list with it isn't a solution. ________________________________ From: keith.gar...@hotmail.com<mailto:keith.gar...@hotmail.com> To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: RE: [powershell] reference elements Date: Mon, 6 Apr 2015 15:59:57 -0700 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> [mailto:listsad...@lists.myitforum.com] On Behalf Of Crawford, Scott Sent: Monday, April 6, 2015 3:56 PM To: powershell@lists.myitforum.com<mailto: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 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1