Link to home
Start Free TrialLog in
Avatar of Techsavy
Techsavy

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Techsavy
Techsavy

ASKER

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.
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?
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
So the first expression was
($_["Categories"]).substring(($_["Categories"]).IndexOf("#")+1)
To return what's before ";#", you could have
($_["Categories"]).substring(0,($_["Categories"]).IndexOf(";#"))