I review for BookLook Bloggers
Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Wednesday, August 22, 2018

Fix AD-USERS Naming Convention [1st letter Uppercase and rest Lower]

Description
Description: This Script Does the following things.
1> Rename Active Directory User's Firstname, Lastname 1st letter to Uppercase ex: JOhn SnOw or john snOn or JOHN SNOW becomes -, John Snow
2> Rename Active Directory User's samaccountname to all lower case example: Jonh becomes - john
3> Rename Active Directory User's Displayname and NAme 1st letter to Uppercase ex: JOhn SnOw or john snOn or JOHN SNOW becomes -John Snow

Source Code

** Recommend to perform in the test environment before moving to the production environment.
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
39
40
41
42
43
44
45
46
47
<#===========================================================================================================================
Script Name: FixADNAmes.ps1
Description: This Script Does the following things.
            1> Rename Active Directory User's  Firstname,Lastname 1st letter to Uppercase ex: JOhn SnOw or john snOn or JOHN SNOW becomes -John Snow
            2> Rename Active Directory User's samaccountname to all lower case example: Jonh becomes - john
            3> Rename Active Directory User's  Displayname and NAme 1st letter to Uppercase ex: JOhn SnOw or john snOn or JOHN SNOW becomes -John Snow

           
      Inputs: OU path if Required to run on an OU
      Outputs: 

Notes: Run as administrator
Date Created: 08/21/2018
      Credits: 
Last Revised: 08/21/2018


** Instructions**
Just Launch Powershell as administrator copy the script and run or save and run it as
FixADNAmes.ps1
=============================================================================================================================#> 
If ( ! (Get-module ActiveDirectory )) {
  Import-Module ActiveDirectory
  Clear-Host
  }

Get-ADUser -filter *  <#-SearchBase 'OU=OU,DC=domain,DC=Local'#>|Foreach{
$newFname=(Get-Culture).textinfo.totitlecase(($_.givenname).tolower())
$newLname=(Get-Culture).textinfo.totitlecase(($_.Surname).tolower())
$name= $newFname + ' ' + $newLname
Set-ADUser $_ -GivenName $newFname -Surname $newLname
Rename-ADObject -Id $_ -NewName $name
Set-ADUser $_.samaccountname -DisplayName $name
Set-ADUser $_.samaccountname -SamAccountName $_.SamAccountName.ToLower()
}



Clear-Host
Write-Host 'The process has been completed' -ForegroundColor Yellow
"Here is how AD users Looks now"
$newU=(Get-ADUser -filter * <#-SearchBase $ou #> -prop Displayname |Get-Random |select -First 1)
$newU |select Name,Displayname,Givenname,surname,samaccountname

Screenshots

Friday, February 28, 2014

How to Send Mail using Power Shell Script

$EmailFrom = "noreply@yourdomain.com"
$EmailTo = "abc@
yourdomain.com"
$Subject = "Notification from ABC Company from Public IP now 10.46 AM"
$Body = "this is a notification from ABC Company.."
$SMTPServer = "X.X.X.X"
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 25)
$SMTPClient.EnableSsl = $false
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password")
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)


Author: Sukanta Kumar Biti

Script Verified. For more info Contact:sukantakumarbiti05@gmail.com

Thursday, December 13, 2012

How to Send an Smtp Email using Powershell – Send-MailMessage

 

Sending an Smtp mail using power shell as been simplified using “Send-MailMessage” Cmdlet

Lets see how to do it !!

Send-MailMessage –From “administrator@careexchange.in” –To “User1@domain.com”, “User2@careexchange.in” -Subject "Mail using Powershell !!" –Body “Body of my Power shell Email” -Priority High -SMTPserver "Exchange2010 Server FQDN"


image

Logging into User1 or User2
Received the below email

image

Mail Generated to User1 and User2 Successfully !

Original Post:

Wednesday, September 12, 2012

Using the Set-ExecutionPolicy Cmdlet


Changing the Windows PowerShell Script Execution Policy
The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies:
  • Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned - Only scripts signed by a trusted publisher can be run.
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted - No restrictions; all Windows PowerShell scripts can be run.
To assign a particular policy simply call Set-ExecutionPolicy followed by the appropriate policy name. For example, this command sets the execution policy to RemoteSigned:

Original Post: