Remove Out-String, because it’s turning your structured data into a flat string. And, keep in mind that the way you’ve written this, $string1 is going to contain a collection of strings. Make sure that’s what you want.
thanks both removing out-string give the below error
Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named ‘Substring’.
At line:3 char:39
$string1 = foreach ($user in $users) {$user.Substring(0,10)}
It looks like you are using a column header (Users). That is why you are getting the error. You need to take one more step and work with type: string not pscustomobject.
Exception calling “Substring” with “2” argument(s): “Index and length must refer to a location within the string.
Parameter name: length”
At H:\EAA\Powers Shell Commands\For Each Example (CSV)Multiple Calendar Perms.ps1:4 char:1
I modified my previous comment. One of your users’ length is longer than 20 characters (Ewan.Frost-Pennington : 21). It will generate an error because of that. You can add an If statement to check user length.
yeah the idea is to ignore everything past the 20 character mark changeing:
Ewan.Frost-Pennington
to
Ewan.Frost-Penningto
hmm even just running this part i get errors,
$Users = Import-Csv "h:\usersCAL.csv"
foreach ($user in $users) {
If ($user.users.length -le 20){
$user.users.Substring(0,20)}}
Exception calling “Substring” with “2” argument(s): “Index and length must refer to a location within the string.
Parameter name: length”
At line:4 char:5