1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#Read file, create users and groups, add user to group, create a directory for each user and share directory #File content: #g,grupo #u,pepe,pass,grupo foreach($val in Get-Content d:\usergroup.txt) { $sli=$val.Split(",") if($sli.Length -eq 2) { Write-Host "Create group" #Create a group $sli[1] net localgroup $sli[1] /add } elseif($sli.Length -eq 4) { Write-Host "Create user" #Crete user $sli[1], value $sli[2] net user $sli[1] /add $sli[2] #Add user to group $sli[3] net localgroup $sli[3] $sli[1] /add #Add directory and share [string]$ruta="d:\"+$sli[1] New-Item $ruta -ItemType directory #Command use string parameters [string]$aux=$sli[1] net share $aux=$ruta } else { Write-Host "Error" } } |