Techsavy
asked on
powershell
Hi,
I have following script:
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
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
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"]).substri ng(($_["Ca tegories"] ).IndexOf( "#")+1)
To return what's before ";#", you could have
($_["Categories"]).substri ng(0,($_[" Categories "]).IndexO f(";#"))
($_["Categories"]).substri
To return what's before ";#", you could have
($_["Categories"]).substri
ASKER
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.