Search code examples
powershellactive-directorypowershell-4.0

PowerShell Active Directory Login Script Auto-Build


I've created an active directory account creation script using powershell 4.

My Boss has stated there's a new policy where we have to build a login script per user, is there a way to do this where it'll build the .bat file and map the drives that we specify within the script?

I know there's a way to build .txt files, but not sure about .bat.

What I need
Select Drives That The user Needs Access To
I need it to build a .bat file, mapping the drives previously specified.
Then move it to the login script folder on the DC, mapped to S


Solution

  • For Future reference to anybody who wants to do this.

    I've managed to resolve it myself after some playing around.

    $NewName = $SAMAccountName
    $extension = ".bat"
    $FileName = "$SAMAccountName$extension"
    $ScriptDrive = "\\IPREMOVED\scripts"
    
    Write-Output "
    BAT CONTENTS" `n`n|FT -AutoSize >>LoginScript.txt
    
    Get-ChildItem LoginScript.txt | Rename-Item -NewName $FileName 
    Move-Item -Path ".\$FileName" -Destination $ScriptDrive