Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Script to create Multiple local Users and set Password never Expire

function create-account ([string]$accountName) {

 $hostname = hostname

 $comp = [adsi]"WinNT://$hostname"

 $user = $comp.Create("User", $accountName)

 $user.SetPassword("P@ssw0rd")

 #$user.SetInfo()

 $User.UserFlags[0] = $User.UserFlags[0] -bor 0x10000 #ADS_UF_DONT_EXPIRE_PASSWD flag is 0x10000

 $user.SetInfo()}

 # Create 30 administrator users named user1 ... user 30

for($i=20; $i -le 23; $i++){

  create-account("TRAIN-$i")

  }


PowerShell Script to automate ESXI host add to vCenter | NTP configure | DNS configure | Place host into maintenance mode

#PowerShell script to automate ESXI configuration part post new ESXI deployment

 

$vCenter= Read-Host "Enter vCenter Name"

$VCCred = Get-Credential

#Add ESXI Host

$ESXI1= Read-Host "Enter ESXI host Name"

$ESXICred= Get-Credential

 

$String= $ESXI1

$String.Substring(0,$String.Length-12) | Out-file 'C:\temp\output.txt'

$Prop= Get-Content -Path 'C:\temp\output.txt'

 

#Connect vCenter 

Connect-VIServer -Server $vCenter -Credential $VCCred

 

#Collect Datacenter details 

$Datacent= Get-Datacenter

 

#Prompt for to enter Datacenter Name, enter here short name inside *.........*, 

$DCM= read-Host "*Enter DC shortname Name inside both*"

 

# String to remove extra character from DC that we are typing manually

$NTP= $DCM

$NTP.subString(1,$DCM.Length-2) |Out-file 'C:\temp\DCName.txt'

$DCName= Get-Content -Path 'C:\temp\DCName.txt'

 

Add-VMHost -Server $vCenter -Name $ESXI1 -Location $DCM -Credential $ESXICred -Force

 

 

Get NTP Server details

==================

 

 

# PowerCli command to COllect NTP server details from existing Datacenter >host

Get-Datacenter | Where-Object {$_.Name -imatch "$DCName"} |Get-VMHost |Where-Object {$_.Name -imatch "$Prop"} |Get-VMhostNTPServer |Out-file 'C:\temp\NTPServer.txt'

$NTPServer= Get-Content -Path 'C:\temp\NTPServer.txt'

 

<#=============================

Get-Datacenter |Where-Object {$_.Name -imatch "$DCName"} |Get-VMHost |Out-File 'c:\temp\VMhost.txt'

$NTPHost= Get-Content -Path 'C:\temp\vmhost.txt'

 

#>

#PowerCli command to add existing NTP server details into new ESXI host

Add-VMHostNtpServer -NtpServer $NTPServer -VMHost $ESXI1 | Where-Object {$_.Name -imatch "$ESXI1"}

 

# PowerCli command to Collect DNS Name, DNS IP, SearchDomain

Get-Datacenter | Where-Object {$_.Name -imatch "$DCName"} |Get-VMHost |Where-Object {$_.Name -imatch "$ESXI1"} | Get-VMHostNetwork | Select-Object DomainName, SearchDomain, DnsAddress |Out-file 'C:\temp\NetInfo.txt'

 

$NetInfo= Get-Content -Path 'C:\temp\NetInfo.txt'

 

 

# PowerCli Command to add DNS Address, SearchDomain

$vmHostNetworkInfo = Get-VmHostNetwork -Host $ESXI1

 

Set-VmHostNetwork -Network $vmHostNetworkInfo -DnsAddress '192.168.1.17','192.168.1.18' -SearchDomain temp.ads.com -DnsFromDhcp $false

 

 

#Put ESXI host into maintenance mode

=================================================

Set-VMHost -VMHost $vmhost -State "Maintenance" 


Script for unattended esxi installation using ftp server | KickStart script


You can use scripts for unattended ESXi installation or upgrade, scripted installations or upgrades provide an efficient way to deploy multiple hosts.


The installation or upgrade script contains the installation settings for ESXi. You can apply the script to all hosts that you want to have a similar configuration.


For a scripted installation or upgrade, you must use the supported commands to create a script. You can edit the script to change settings that are unique for each host.


The installation or upgrade script can reside in one of the following locations:


FTP server

HTTP/HTTPS server

NFS server

USB flash drive

CD-ROM drive

In my lab I am keeping the installation script in FTP and HTTP server.


You can download the script from below link and save the script win KS.CFG

http://www.mytechinfoit.com/2022/04/script-to-automate-esxi-deployment.html 


Steps to configure FTP server.


Login to server

Go to server manager

Add Roles and features -> Follow the screen

Check web server IIS

FTP server

Select FTP service



Click next and follow the screen and install

Once installation complete

Open IIS manager




Right click on site and click Add  FTP site


Give the FTP site name

In content directory give the physical location of script file

I have kept script file in c:\esxi folder



Click next 

Select IP address to bind the address, in my Lab setup I am using single IP, if there is multiple assigned on the server then it will show in list


Select No SSL



In Authentication type

Select Anonymous

And anonymous users


In permission 

Select Read


Then click finish

Now select newly created FTP site SK-CFG

Click FTP authentication and enable Anonymous authentication if it is not already enabled

Once you enable it then anyone can access this FTP content without login.



Also click on FTP authorization rule to recheck whether anonymous users are allowed or not



Now go to the client machine and check whether FTP is working or not.

Open browser and enter FTP path-> ftp://192.168.1.16/ 


Now FTP page is opening without entering any user ID or password


Steps to install unattended ESXI 


If you are using physical server for deployment, then mount ESXI ISO and boot the server using CD/DVD

And follow below steps, in my case I am deploying ESXi in VMware workstation.

Steps will be the same for both Physical and Virtual only, the booting process will be different.


For a physical server you need to launch iLO console and mount ISO and boot from there.

In the VMware workstation we need to edit the VM setting and assign the ISO path and boot the server.



Once you will boot the server using ISO at first boot press SHIFT=O to edit boot options 





Now enter FTP address one temp IP to communicate with the FTP server like below.



Press enter.

Now installation has started


Post installation server will auto reboot and do the entire configuration that has been updated in the script.

Finally installation completed with the same configuration that had updated in script file.



Thank you!!!!











Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is 10.0.0.1/2 You need to connect your laptop and storage with...