Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:03:23+00:00 2026-06-18T12:03:23+00:00

I am using powershell in conjunction with sharepoint 07 to list some stuff out.

  • 0

I am using powershell in conjunction with sharepoint 07 to list some stuff out. I am trying to allow a (power) user to specify which Fields they want to display.

For example, I could run my code as follows:

.\psextractor -fields “Type|name|User Desc

After doing this I would get a list of files displaying the fields listed above. Currently I am using the Select-Object identifier and I was wondering if this was possible. If not, is there a way to do this without using the create-object cmdlet?

My code:

#$Args
if($Args[0] -eq "-fields" -and $Args.Count -ge 2){
    $flds = $Args[1].split("|")
}

#Later in code
 $web.Lists | foreach{
    $lib = $_
    if($lib.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary 
           -and $lib.BaseTemplate -eq [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary){
        $lib.Items |  Select-Object DisplayName,
                  @{n=$flds[0];e={$_.Item($flds[0])}} ,
                  @{n=$flds[1];e={$_.Item($flds[1])}}
                  #, etc, etc

    }

 }

EDIT:
I used Graimer’s solution below with a few tweaks

SOLUTION:

param([object[]]$flds)
$props=@() #globally declared since some of this is done in functions later

$mflds = $("Author","Created","Modified","Modified By") #mandatory fields
$mflds | foreach{
    if($flds -notcontains $_){
        $flds += $_
    }
}
#had to use regular for loop because the $_ identifier was conflicting
for ($i =0; $i -lt $flds.Count; $i++) { 
    $props += @{n=$flds[$i];e=([Scriptblock]::Create("`$_[`$flds[$i]]"))}
}
#other mandatory custom fields
    #the create method could have been used here
$props += @{n="FileName";e={"$($_.Item('Name'))"}}
$props += @{n="Url";e={"$wburl/$($_.Url)"}}

#Later in code
 $web.Lists | foreach{
    $lib = $_
    if($lib.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary 
           -and $lib.BaseTemplate -eq [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary){
        $lib.Items |  Select-Object -property $props

    }

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:03:25+00:00Added an answer on June 18, 2026 at 12:03 pm

    I would suggest taking in the paramters as a normal string[] (Array) parameter, and use it to create an array of hashtables (custom expressions for Select-Object). Then supply the hashtable with Select-Object. Ex:

    param (
        [String[]]$Fields
    )
    
    #Create property-array for Select-Object
    $props = @()
    
    #Add mandatory displayname property
    $props += @{n="DisplayName";e=([Scriptblock]::Create("`$_.DisplayName"))}
    
    #Add user-defined fields
    foreach ($field in $Fields) { 
        $props += @{n=$field;e=([Scriptblock]::Create("`$_.Item($field)"))}
    }
    
    #Later in code
    $web.Lists | foreach{
        $lib = $_
        if($lib.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary  `
        -and $lib.BaseTemplate -eq [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary)
        {
            $lib.Items | Select-Object -Property $props
        }
    
     }
    #Usage: .\psextractor -Fields "Type", "Name", "User", "Desc"
    #This will list all fields specified after '-Fields'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to grab out some information from Active Directory using Powershell, but I
I'm trying to develop some tool in C# which is using PowerShell. However, I
I'm using PowerShell and I'm trying to figure out how to compare the hashes
I'm trying to retrieve some information about my hard drives using PowerShell (very new
I am trying to create a file using powershell in a specific user context.
I've been trying to update a SharePoint calendar using PowerShell (say I have a
I'm using PowerShell for auto-deploying website, and recently found AppPool setting which cannot be
I am trying to create a new web application using PowerShell. I keep getting
NOTE: I'm using PowerShell 2.0 on Windows Vista. I'm trying to add support for
I'm using PowerShell 2.0 and I want to pipe out all the subdirectories of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.