Get duplicate users on AD server and append a suffix
I want to append a suffix to differentiate users having same samaccountname.
* Create new AD user
* Get samaccountname of created user($newsam)
* Get list of samaccountname for all users in AD ($allsams)
* Match new samaccountname with list of samaccountname to detect accounts with duplicate samaccountnames
* Append suffix 1 to new user samaccountname and 2,3,4.... as suffixes to others created afterward
Thanks for your help!
do you know?
how many words do you know
See also questions close to this topic
-
How to require a dll inside .psd1 for a .psm1 that is being invoked from a .ps1?
I read a lot of the answers here and I can't seem to find what I am looking for. So please bear with me.
Each psm1 is a class.
I have:
Main.ps1
Modules/module01.psm1
Modules/module02.psm1
DLL/dllInQuestion.dll
I am trying to load a dll to use inside module02.psm1. I know that in order to do so I have to require it inside a .psd1. I created a psd1 for module02 and put it in the same folder and imported it like this "Import-Module" before the code but it didn't work.
I also tried to create a psd1 for Main.ps1 but it didn't work.
Can I require (using using module statements and Add-Type) all modules and dll inside a .ps1 script and require it inside a .psd1 for Main.ps1?
Thank you.
-
Subprocess $Env:Path python: The filename, directory name, or volume label syntax is incorrect
I am trying to change the windows environment variables, but I am having trouble doing so.
Before I tried to use
os.environ()
I tried out using powershell commands and adding a string to$Env:Path
which worked, but removing it with:$env:Path = ($env:Path.Split(';') | Where-Object -FilterScript {$_ -ne $Remove}) -join ';'
however didn't seem to remove it being my path I want to add
("FFmpeg:C:\Users\user\AppData\"
) and adding it with+= C:/Users/etc..
didn't see, the way to go.Another way I tried to add vars through the Powershell commands was using
SetEnviormentVariable
and it seemed to work fine but once I restarted my PC the entry I made with it was gone.Sadly though all in the end all my powershell commands didn't work with subprocess. Whatever command it was I was using here I got:
PS C:\Users\Me123> python >>> import subprocess >>> subprocess.run("$Env:Path", shell=True) The filename, directory name, or volume label syntax is incorrect. CompletedProcess(args='$Env:Path', returncode=1)
-
Can I ship Test-Json from pwsh with my software?
Is it possible to ship cmdlet Test-Json only with my software or a dll that contains it from pwsh? I downloaded the entire pwsh zip file but not sure which one contains it.
My software is going to run on PCs that only have PS 5. I cannot install other software on these machines.
-
Active Directory replication between multiple controllers fails
I am coming to the forum because I have a big problem with the replication of my domain controllers.
I explain the situation:
Context :
I have 2 local sites connected with IPSec, let's call them site A and site B. In each site I have two domain controllers let's call them for site A DC1 and DC2 and for site B DC3 and DC4.
The 4 controllers are synchronized between them in inter site and intra site.
The 2 DC of site A are virtualized with Hyper V. The 2 DC of site B are physical.
Normally DC1 is the master DC.
Problem:
I ran a domain configuration audit script on DC1 that was supposed to run in audit mode but unfortunately made big changes on the domain. Basically the script applied the best practices of all the CIS checkpoints (which in fact is fine) but it impacted the business of the company. This is because all the DC's synced with the DC1 which pushed the changes automatically to the other DC's.
Fortunately, we have an extremely recent backup (snapshot) of the hyper V that we used to restore the DC1. However, when we start the restored DC1 VM, the other DCs (2,3,4) that have the bad changes replicate them to the DC1 automatically (15 seconds) so we can't restore our domain controllers from the DC1 snapshot.
In order to find a solution, we disabled the auto replication in INBOUND and OUTBOUND on the DC2,3,4 (repadmin /options DCx +DISABLE_INBOUND_REPL) (repadmin /options DCx +DISABLE_OUTBOUND_REPL) then restored the snapshot of the DC1 VM and launched the DC1. It works perfectly, the DC1 keeps the good modifications (the old ones, before the script execution), so we now want to apply the settings of the DC1 on all the DCs to get a homogeneous domain. So we force the replication of DC1 on the other DCs with the command: Repadmin /syncall DC1 /APed.
This propagated the good configuration of DC1 on the other DCs so it's perfect.
However, by reactivating the INBOUND and OUTBOUND (repadmin /options DCx -DISABLE_INBOUND_REPL) (repadmin /options DCx -DISABLE_OUTBOUND_REPL) auto replication on the DCs, the bad modifications unfortunately reappeared and propagated on all the DCs almost immediately.
How is this possible knowing that at a given time "T" the 4 domain controllers all had the old good configuration (before the script was executed)?
Where did the DC's go to get the wrong configuration (after the script was executed)?
How do we keep the right config on all the DCs once we reactivate the replications by reactivating the INBOUND and OUTBOUND?
I thank you in advance for your answers, the situation is very critical.
-
VBScript object.GetInfo() returning attribute names different from .NET DirectorySearcher
I have been tasked with writing a C# replacement for a VBScript process that gets a list of all Active Directory user accounts with various object attributes.
The VBScript is taking an ADObject and invoking a method called
.GetInfo()
. I do not know anything about.GetInfo()
(or VBScript either), but it is returning a lot of attributes that myDirectorySearcher
is not.Specifically,
.GetInfo()
returns attributes called "PasswordExpirationDate" and "PasswordLastChanged". But MyDirectorySearcher
results do not include those attribute names.SearchResultCollection results; DirectoryEntry de = new DirectoryEntry("LDAP://RootDSE"); DirectorySearcher ds = new DirectorySearcher("LDAP://" + de.Properties["defaultNamingContext"][0].ToString()); ds.PageSize = 1000; ds.Filter = "(&(objectCategory=*)(objectClass=*))"; results = ds.FindAll();
This code does return attributes called "AccountExpires", and "PwdLastChanged". Also,
.GetInfo()
will return an attribute called "AccountDisabled" that does not exist in myDirectorySearcher
results. InDirectorySearcher
, the account disable status is in one of the UAC bits that I have decoded.Is
.GetInfo()
"black boxing" and returning these same attributes just with different names? Or are they truly different attributes thatDirectorySearcher
is just not finding? -
i used Powershell in a script to execute and install a app in a computer remotly, I Used psexec
well i have a little script this should execute and install one application but really in the other computer hasn't installed i'll want to install application in the other computer
the files txt have the name of the computer yours hostname, when i execute of the script i look that my computer can connect to other computer by psexec and i can watch that appears on my screen in summary "psexec v2... - execute processes remotly, copyright, sysinternals" but after the application has not installed what i can do? i have problems in the last line
& C:\pstools\psexec.exe -u $user -p $password \$destination\c$ $app
$Computers = Get-content "C:\Users\marc\Documents\computer.txt" $destination = Get-content "C:\Users\marc\Documents\destination.txt" $File= "c:\Documents\program.exe" $app="c:\program.exe /clone_wait /s /v' /qn PROGTYPE=ENTEGRA REBOOT=Supress'" Foreach ($destination in $Computers) { $Test = Test-Path -path "\\$destination\c$" If ($Test -eq $True) {Write-Host "The path exists, the software will be installed in $destination."} Else {(Write-Host " the path does not exist, therefore it will be created in $destination and the installation will start")} Echo "Copying Files to C:\$destination" Copy-Item $File "\\$destination\c$" echo "Second part : installing the software on $destination" & C:\pstools\psexec.exe -u $user -p $password \\$destination\c$ $app }
-
Script to double quotes
I have a keyboard that does not have double quotes, when I need to use it, it's very difficult to remember the FN. How can I create a script so that when I press LShift + Escape it puts a double quote?