Stopzilla AVM

Sunday, March 31, 2013

Create OU in Active Directory using PowerShell

Here I’ve written code for creating OU in Active directory.
First of all will get Domain name and pass Distinguished name to function DNStoDN.
   1: function PassPath

   2: {

   3:     

   4:     $DC = Convert-DNStoDN (gwmi WIN32_ComputerSystem).Domain

   5:     

   6:     return "OU=$OU, $DC"

   7: }

Then split DistinguishedName using function DNStoDN


   1: # This function to get 
   2: function Convert-DNStoDN ([string]$DNSName) 
   3: { 
   4:    #  Create an array of each item in the string separated by "." 
   5:    $DNSArray = $DNSName.Split(".") 
   6:   # Let's go through our new array and do something with each item 
   7:    for ($x = 0; $x -lt $DNSArray.Length ; $x++) 
   8:       { 
   9:         #I don't want a comma after my last item, so check to see if I am on my last one and set 
  10:         # $Separator equal to nothing. 
  11:         # Remember that we need to go to Length-1 because arrays are "0 based indexes" 
  12:          if ($x -eq ($DNSArray.Length - 1)){$Separator = ""}else{$Separator =","} 
  13:          [string]$DN += "DC=" + $DNSArray[$x] + $Separator 
  14:       } 
  15:    return $DN 
  16: }


Now I’ll check OU is exists, If it does not will create new OU. You can change the name of OU given in the beginning.




   1:  

   2: function CheckOU

   3: {

   4: [string] $path = PassPath  #Calling function PassPath

   5: [string] $fPassPath = Convert-DNStoDN (gwmi WIN32_ComputerSystem).Domain

   6: try {

   7:      if(([adsi]::Exists("LDAP://$fPassPath")))

   8:      {

   9:         #return $true #Throw("Supplies Path does not exists.")

  10:         if(([adsi]::Exists("LDAP://$path")))

  11:         {

  12:             return $true

  13:         }

  14:      }    

  15:     }

  16: catch {

  17:        Write-Host "Please check Domain of your machine" -ForegroundColor red  

  18:        exit   

  19:       }

  20: }

  21:  

  22: if((CheckOU))

  23: {

  24:     Write-Host "OU exits"

  25: }

  26: else

  27: {

  28: try {

  29:         [string] $fPassPath = Convert-DNStoDN (gwmi WIN32_ComputerSystem).Domain

  30:         Write-Host $fPassPath

  31:         if(([adsi]::Exists("LDAP://$fPassPath")))

  32:         {

  33:             $Connect = [adsi]"LDAP://$fPassPath"

  34:             

  35:             $CreateOU = $Connect.Create("OrganizationalUnit","OU= $OU")

  36:             $CreateOU.SetInfo()

  37:             if((CheckOU))

  38:             {

  39:                 Write-Host "`nOU" $OU " has been created!"  -ForegroundColor green

  40:                 

  41:                 

  42:     

  43:             }

  44:         }

  45:     }

  46: catch {

  47:          Write-Host "Can't create OU." -ForegroundColor red

  48:          exit

  49:       }

  50: }

Here is the complete code snippet.

Run this script with Administrator privilege.


   1: Import-Module ActiveDirectory
   2:  
   3: $OU = "myOU" # Organizational Unit Name
   4:  
   5:  
   6: # This function to get 
   7: function Convert-DNStoDN ([string]$DNSName) 
   8: { 
   9:    #  Create an array of each item in the string separated by "." 
  10:    $DNSArray = $DNSName.Split(".") 
  11:   # Let's go through our new array and do something with each item 
  12:    for ($x = 0; $x -lt $DNSArray.Length ; $x++) 
  13:       { 
  14:         #I don't want a comma after my last item, so check to see if I am on my last one and set 
  15:         # $Separator equal to nothing. 
  16:         # Remember that we need to go to Length-1 because arrays are "0 based indexes" 
  17:          if ($x -eq ($DNSArray.Length - 1)){$Separator = ""}else{$Separator =","} 
  18:          [string]$DN += "DC=" + $DNSArray[$x] + $Separator 
  19:       } 
  20:    return $DN 
  21: }
  22:  
  23:  
  24: function CheckOU
  25: {
  26: [string] $path = PassPath  #Calling function PassPath
  27: [string] $fPassPath = Convert-DNStoDN (gwmi WIN32_ComputerSystem).Domain
  28: try {
  29:      if(([adsi]::Exists("LDAP://$fPassPath")))
  30:      {
  31:         #return $true #Throw("Supplies Path does not exists.")
  32:         if(([adsi]::Exists("LDAP://$path")))
  33:         {
  34:             return $true
  35:         }
  36:      }    
  37:     }
  38: catch {
  39:        Write-Host "Please check Domain of your machine" -ForegroundColor red  
  40:        exit   
  41:       }
  42: }
  43:  
  44: if((CheckOU))
  45: {
  46:     Write-Host "OU exits"
  47: }
  48: else
  49: {
  50: try {
  51:         [string] $fPassPath = Convert-DNStoDN (gwmi WIN32_ComputerSystem).Domain
  52:         Write-Host $fPassPath
  53:         if(([adsi]::Exists("LDAP://$fPassPath")))
  54:         {
  55:             $Connect = [adsi]"LDAP://$fPassPath"
  56:             
  57:             $CreateOU = $Connect.Create("OrganizationalUnit","OU= $OU")
  58:             $CreateOU.SetInfo()
  59:             if((CheckOU))
  60:             {
  61:                 Write-Host "`nOU" $OU " has been created!"  -ForegroundColor green
  62:                 
  63:                 
  64:     
  65:             }
  66:         }
  67:     }
  68: catch {
  69:          Write-Host "Can't create OU." -ForegroundColor red
  70:          exit
  71:       }
  72: }


Thanks.


Thursday, March 14, 2013

SharePoint 2010 Service Account Password Change

My SharePoint Farm has multiple application pools including SharePoint Services running.

And each Application Pool is running on different service account.

To check which application pool is running using which service account.

Go to Run >> Type inetmgr. This will open Internet Information Services Manager.

Click on Application Pool and you can see Identity of Application pool which is Service account.

AppPool

When we create Application Pool or Application Service and choose new service application pool account, this account

get registered to Manage Accounts under Security.

Path will be Central Administration >  Security > Manage Accounts

We can see here are all service accounts are registered.

Manage Accounts

If you want to Check password of service account you can check using PowerShell command.

Open Windows PowerShell Module from All Application Program.

type below PowerShell Command.

Get-WmiObject –Namespace root/MicrosoftIIsV2 –Class IIsApplicationPoolSetting –Property Name, WAMUserName, WAMUserPass | Select Name, WAMUserName, WAMUserPass

and it will show all passwords of particular service account name.

 ServiceAccountPassword

This will help you in case you forget your AppPool Service Account password.

Now, we will change password of service account which is running a web application name Tesst – 45380. And you can see

the service account name is spdev\testpass and password is P@ssw0rd3

For changing password of spdev\testpass  go to Central Administration > Security > Manage Accounts

look for spdev\testpass and edit.

Now check box named Change Password Now and select Set account password to new value.

enter new password and click on ok.

ChangePass

 

To confirm password is changed or not you can run above PowerShell script.

 

Thanks for reading,

Any query, please post comment.

 

Tuesday, December 25, 2012

Install and Configure SharePoint Server 2013 step by step

In this blog post I am covering all basic required steps of SharePoint 13 installation. And have divided this in 4 parts.

1) Install Windows Server 2012 and Active Directory configuration.

2) Install SQL Server 2012.

3) Install and configure SharePoint Server 2013 .

4) Configure SharePoint Server Service Applications

5) Create your first web application on SharePoint Server 2013.

Installation and configuration of Windows Server and SQL server have done more specific to build SharePoint Server farm prospective.

For example, Permissions given to Service accounts during installation of windows server. Installation of SQL server and SharePoint Server have done by specific service account.

If you have any query, please post comment.

Thank you.

 

Create Web Application on SharePoint Server 2013

This blog post is specially for SharePoint beginners. If you have read my previous blog about SharePoint Server 13 installation and configuration. This blog is about creating web application and creating site collection.

So let’s open SharePoint Central Administration Page.

Navigate to Manage Web Applications >> Click on New

IIS web site name : <Enter name>

Select Port : ( I don’t have any web application created before, So it’s taking port 80)

CreateNew

 

Application Pool Name : <Enter name>

note : I am going to create Team Site under this web application, So I’ve given TeamSite name to Application name and 80 to remember this application pool is on port 80.

 

PublicUrl

 

Content Database name : I’ve added _80 to differentiate in Content database.

ContentDB 

We can select Service Application those will be connected to web application we are creating.

SAC

Click on OK to create web application. This will take few seconds.

Once the web applicaiton is created. Go to Application Management >> Create Site Collection

Select Web Application which was just created.

Title : <Enter name>

TeamSiteCollection

Select Template : Team Site

Select Experience Version : 2013

Primary site collection administrator : spadmin

Template

note : primary and secondary admin have full permission on site collection.

click on Ok.

Visit just created Team site collection.

TeamSite

Give permissions to Active Directory users to site collection.

Navigate to Site Contents which is on left panel of the Team Site.

Settings

Again go to Settings

SiteSetting

People and groups

Add new user to Team site members this group has contribute permission Type >> NT Authority\authenticated users

NTUsers

Go to home page by clicking on Team site link and sign in with different user.

Thanks.

Also read :

 

Monday, December 24, 2012

Install and Configure SharePoint Server 2013 Step by Step

 

You are reading :  SharePoint Server 2013 installation Part 3

In previous post we’ve installed SQL Server 2012, Now for SharePoint installation I’ve logged in with SPAdmin

account, and also have created one more account for which will have administrator rights on SharePoint farm i.e. svcSPFarm.

1) Download : SharePoint Server 2013

2) Mount ISO file. and start installation process.

InstallationScreen

Before starting installation SharePoint Server, need to install software prerequisites.

So click on Install software prerequisites.

Note : you need active internet connection.Because it downloads updates from Microsoft Download Center.

Prerq

Accept and terms and licence agreement and go next.

CompletePrereqInstallation

Once installation of Prerequisite is done. Click on Install SharePoint Server

 InstallationScreen

Enter product key and Continue.

Accept Terms and Continue.

Keep Path of Server as it is and click on Install Now

PathofServerl

This will install SharePoint Server on your machine.

InstallationProcess

Next step is to Run the SharePoint Configuration Wizard

RunWizard

By clicking on Close button, Wizard will run. If you want to run it later you can find it in start menu.

WelcomeSharePoint

Click on Next.

ServiceRestart

Click on Yes.

CreateNewServerFarm

Select Create a new server farm. and click Next

Enter Database server name (Server name on which SQL Server is installed).

Username : zsdev\svcSPFarm (which I’ve created in Active Directory) This Service Account will have full access on

SharePoint Config Database

Password : (Password set for svcSPFarm account)

DatabseConnection

SP13 is the server name where SQL Server is installed. click Next

Enter Passphrase. and don’t forget it. because next time when you will need to reconfigure farm at the time of update installation. It will ask you for Passphrase.

Passphrase

Specify Central Administration Portal port. you can change it if you want.

keep authentication provider : NTLM

SpecifyPort 

I’ve change port number to 1111 from 17685.

CompleteConfigWizard

Click Next.

ConfigProcess

and Configuration is completed.

CompleteConfig1

Click on Finish button. This will open Central Admin web page.

NoConfigSharePointFarm

Click on Cancel button for SharePoint Configuration Farm. It will redirect you to Central Administration.

IE

Here it is complete SharePoint Server Configuration.

 

Also read :

Thanks,

If any query please post comments