I tried the following code to extract the domain and it worked just fine when defining a variable
$ADS = 'CN=Lamda,OU=OU_Bloquage,DC=Adminstrateur,DC=6NLG-AD'
But things didn't go well when I changed $ADS
into
$ADS = Get-ADUser -Identity 'Lamda' -Properties DistinguishedName |
select DistinguishedName`
The result that I want to have is:
DC=Administrateur,DC=6NLG-AD`
Below is the code that I've wrote
$ADS = Get-ADUser -Identity 'Lamda' -Properties DistinguishedName |
select DistinguishedName
$pattern = '(?i)DC=\w{1,}?\b'
([RegEx]::Matches($ADS, $pattern) | ForEach-Object { $_.Value }) -join ','
select DistinguishedName
->select -Expand DistinguishedName
– Ansgar WiechersSelect-Object
, or address the property in your code. use$ADS.DistinguishedName
instead of$ADS
– Lee_Daileyselect DistinguishedName -> select -Expand DistinguishedName
and tested it but the following error occurs :Move-ADObject:Operation could not be affected because object parent was not created or was deleted
– Mohamed Khalil HannachiMove-ADObject
. The question is only how to split the distinghuished name.. – Theo