PowerShell Codes' Sample


$UserList = Import-Csv -Path 'C:\Users\Administrator\Desktop\CreatingBulkUser\staff.csv'

foreach ($User in $UserList) {

     $Attributes = @{

        Enabled = $true
        ChangePasswordAtLogon = $false
        Path = "OU=Staff,DC=els,DC=xxxxxss,DC=org"

        Name = "$($User.First) $($User.Last)"
        UserPrincipalName = "$($User.Username)@els.xxxxxss.org"
        SamAccountName = "$($User.Username)"

        GivenName = $User.First
        Surname = $User.Last
        Company = $User.Company
DisplayName = "$($User.First) $($User.Last)"
     
        AccountPassword = "testpassword" | ConvertTo-SecureString -AsPlainText -Force


     }

    New-ADUser @Attributes

}

This code creates users in AD
===============
Add-ADGroupMember -Identity "Staff" -Member mike

The powershell code above adds mike into Staff security group.
===============
Set-ADAccountPassword mike -Reset -NewPassword (ConvertTo-SecureString -AsPlainText “Password2017” -Force)

The powershell code above reset mike's password to Password2017
===============
Set-ADUser -Identity mike -ChangePasswordAtLogon $true

The powershell code above force mike to change his password.
===============
Set-ADAccountPassword mike -Reset -NewPassword (ConvertTo-SecureString -AsPlainText “Password2017” -Force)
Set-ADUser -Identity mike -ChangePasswordAtLogon $true

The powershell code above reset mike's password to Password2017 and force mike to change his password.
===============
$UserN = Get-ADUser mike -Properties pager
$UserN.pager = "1144"
Set-ADUser -instance $UserN

The powershell code above changes mike's pager to 1144
===============
gpupdate /force

Computer Policy and User Policy update
===============
Import-module ActiveDirectory
Import-CSV "C:\Users\Administrator\Desktop\CreatingBulkUser\pager.csv" | % {
$User = $_.Username
$pager = $_.Card_ID_Number

$UserN = Get-ADUser $User -Properties pager
$UserN.pager = $pager
Set-ADUser -instance $UserN
}

The powershell code above changes the users' pager as in the test.csv file.
===============
Import-Module ActiveDirectory
$users = Get-ADUser -Filter *
foreach ($user in $users)
{
    $email = $user.samaccountname + '@pioneercss.org'
    Set-ADUser -Identity $user.samaccountname -EmailAddress $email
}


The powershell code above changes all users' email address to username@pixxxxxxxx.org
===============
Import-Module ActiveDirectory
$users = Get-ADUser -Filter *
foreach ($user in $users)
{
    $displname = "$($User.GivenName) $($User.Surname)"
    Set-ADUser -Identity $user.samaccountname -DisplayName $displname
}


The powershell code above changes all users' display name to their first and last name.
===============

Comments

Popular posts from this blog

Synology DiskStation Quick Installation

iBoss Tips&Problems

Sonicwall; Open a port and how to use sonicwall wizard