Our Accountstruture is not uniform. So I have to create my own view. Everythings works fine until i want to sort my seleted Data. I have no idea why it wont work. Every Idea is welcome.
Greetings, Franken
$Auswert = @(
'CN= Bachhuber Hermann PN78945, DS, DA'
'CN= Al Husainy Mohammed Wessam PN55710, DS, DA'
'CN= Max Erwin Wundermann PN12345, DS, DA'
)
foreach($INDS in $Auswert)
{
$DS = @( $INDS -split ",")
#Abschneiden der ersten drei Zeichen des Datensatzes
$DS = $DS[0].Substring(3)
#Füllen Array mit Accountname
$DS = @( $DS -split " ")
#Z-Nummer / letzter Eintrag im Array
#Write-Host $DS[-1]
$j=0
$KDS=@()
for ($j=0; $j -le ($DS.Length-1); $j++)
{
if ( $j -eq 0) { $KDS = $DS[$j] } #Kein Leerzeichen am Anfang
elseif ( $j -eq $DS.Length-1) { $KDS = $KDS + "`r`n" } #CRLF am Ende
else { $KDS = $KDS +" "+$DS[$j] }#Verbinden der Namen mir Leerzeichen
}
#Array mit AcountName füllen
$User += $KDS
#Array mit PN-Nummer füllen
$PNummer += $DS[-1]
}
$User = $User | sort
$PNummer1 = $PNummer | sort
foreach($mem in $User)
{
$mem
}
foreach($mem in $PNummer)
{
$mem
}
$Auswert = @(
‘CN= Bachhuber Hermann PN78945, DS, DA’
‘CN= Al Husainy Mohammed Wessam PN55710, DS, DA’
‘CN= Max Erwin Wundermann PN12345, DS, DA’
)
foreach($INDS in $Auswert)
{
$DS = @( $INDS -split “,”)
#Cut of the first three characters of the data set
$DS = $DS[0].Substring(3)
#Filling Array with Accountname
$DS = @( $DS -split " ")
$j=0
$KDS=@()
for ($j=0; $j -le ($DS.Length-1); $j++)
{
if ( $j -eq 0) { $KDS = $DS[$j] } #No space at the beginning
elseif ( $j -eq $DS.Length-1) { $KDS = $KDS + "`r`n" } #CRLF at the end Ende
else { $KDS = $KDS +" "+$DS[$j] }#Connect the names with spaces
#Array filling with AcountName
$User += $KDS
#Array filling with PN-PN-Number
$PNummer += $DS[-1]
You might elaborate a little more detailed what your actual problem is. It is not clear what is not working for you. You might share an example of the desired output as well. And please format all of your code as code. Thanks.
If I understand it right you should create your output objects completly first and sort them afterwards. It might help when you write your code a little more verbose … like Sort-Object -Property sAMAccountName for example.
If you feel more comfortable asking technical questions in your native language - there are some German Powershell forums availabe. Like