Re: Create on-premises Active Directory user with Flow
I was able to create a unique password for each user. When creating the csv I used a randomly generated GUID and grabbed the first x number of characters and set that for the password field.
The script to monitor is fairly simple:
$folder = # Enter the root path you want to monitor.
$filter = '*.csv' # You can enter a wildcard filter here.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
Invoke-Item 'Folderpath.bat'
}
Since I am not logged onto a server 100% of the time I set a task schedule to call a .bat which will open up this script with a persistent window (as it requires an active PS window). That is done with a .bat (ran every 5 minutes through Event Scheduler to ensure it stays up)
Powershell.exe -noexit "& "Path.ps1
The "Folderpath.bat" mentioned in the first block of code with "Invoke-Item" is what invokes this
Powershell.exe -executionpolicy remotesigned -File Path-To-Create-User.ps1
That .ps1 is my create AD user script. You can find plenty of guides on how to customize that to your needs. The important parts (for this method anyway) is that you need it to run right as the .csv is entered and then delete the .csv as it pulls every csv in the folder. I'm sure you could do a foreach but I'm too lazy for that and this works perfectly fine as I have a backup of the csv in a SharePoint drive.
Just start the create-user.ps1 like this:
Import-Module ActiveDirectory
$CSVPath = Get-ChildItem C:\Path-To-Folder-With-CSV -Filter *.csv | select -ExpandProperty FullName
$User = Import-Csv -Delimiter "," -Path $CSVPath
And do a
Remove-Item -Path $CSVPath
To delete the csv that was just created.
I hope that is clear enough to follow, I'd be happy to clarify or help further if I can.