I have the following code:
$TodayDate = Get-Date -Format "dd-MM-yyyy"
$Student = Student01 - Project 01-02 - $TodayDate
Write-Host -NoNewline -ForegroundColor White "$Student"; Write-Host -ForegroundColor Green " - was delivered!"
This script returns in the console:
Student01 - Project 01-02 - dd-MM-yyyy - was delivered
How is it possible to return only everything after the first "-"?, that is Project 01-02 - dd-MM-yyyy - was delivered?
I thought about using .split, but I couldn't make it work so that it returns everything after the first "-".
-Splitto split it in 2, then grab the 2nd string after-.-Replacecould also work here. Can you update your post with your attempts at this?-split, but I used.Replaceand it worked, the final script looked like this:Write-Host -NoNewline -ForegroundColor White "$(($Student).Replace("Student01 -", "$null"))"; Write-Host -ForegroundColor Green " - was delivered!"