powershell

Hi,

I have following script:
#Retrieving the Web Site with List
$MyWeb = Get-SPWeb "http://MySite"

#Get the List name
$MyList = $MyWeb.Lists["MyList"]

#Get The View
#Change the name of the view
$MyView = $MyList.Views["My View"]

#Get the Items from the view
$MyItems = $MyList.GetItems($MyView)

#Get Specific field items and export it to a csv file
$MyItems | %{ select-object -input $_ -prop @{Name='ID';expression={$_.ID;}}, @{Name='Content Type';expression={$_["x. Type"];}}, 
@{Name='Item Name';expression={$_["Item Name"];}}, @{Name='Categories';expression={$_["Categories"];}}, 
@{Name='Item Activity';expression={$_["Item Activity"];}}, 
@{Name='attending';expression={$_["attending"];}}; } | Export-Csv -Path C:\MyExports\export.csv

Open in new window

Now, the categories field is a lookup field how do use substring after function for the look up field so that I get the text after "#" character?
TechsavyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
I'm not sure if I understand exactly what you're looking for, however try this and see if it fits.  BTW, it's simpler to just pipe to Select-Object, rather than using it within a ForEach so I modified the code to do that.
#Get Specific field items and export it to a csv file
$MyItems | select-object -prop @{Name='ID';expression={$_.ID}},
                                @{Name='Content Type';expression={$_["x. Type"]}},
                                @{Name='Item Name';expression={$_["Item Name"]}},
                                @{Name='Categories';expression={ ($_["Categories"]).substring(($_["Categories"]).IndexOf("#")+1) }},
                                @{Name='Item Activity';expression={$_["Item Activity"]}},
                                @{Name='attending';expression={$_["attending"]}} |
 Export-Csv -Path C:\MyExports\export.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TechsavyAuthor Commented:
Hi footech,

Thank you for the solution. What function I use to get anything before ';#' to get the ID of the LookupList Item? SharePoint Stores lookup field values as 1;#LookupValue so, I need to extract the string before ;# it could be any number.
0
footechCommented:
I don't understand what you're asking.  I don't have a environment where I can test this out so you'd need to show me exactly what is being returned now.  Let me know if the code I provided is working for you.  Is this a separate question than your first one, or do you just need a modification of what I provided?
0
TechsavyAuthor Commented:
Hi footech.

The solution that you gave me worked for the case where I wanted to return everything after '#'. But now I need to find a way to extract everything that appears before ';#' in a string that is always formatted 12;#somestring. Please note that the number before ;# could be anything from 1 to 20000
0
footechCommented:
So the first expression was
($_["Categories"]).substring(($_["Categories"]).IndexOf("#")+1)
To return what's before ";#", you could have
($_["Categories"]).substring(0,($_["Categories"]).IndexOf(";#"))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.