Posts

Showing posts with the label Powershell for windows admins

Default powershell commands not getting executed , getting command not recognized.

I was working on some weird cases that some of the basic powershell commands are not getting  executed in the machine and i came to know that the powershell modules are not getting loaded due to which default modules are not getting loaded in the psmodule path. Resolution would be to run the below commands: $PSModulePath = Get-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" $newPSModulePath = $PSModulePath.PSModulePath + ";C:\Windows\System32\WindowsPowerShell\v1.0\Modules" Set-ItemProperty -Path "HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "PSModulePath" -value $newPSModulePath Else you need to create a PSModulePath value under the below path : HKLM:SYSTEM\CurrentControlSet\Control\Session Manager\Environment and need to enter the value of path mentioned below in the PSModulePath key : %SystemRoot%\system32\WindowsPowerShell\v1.0\M

Auto creation and deletion of Snapshots in Vsphere Environment using Powercli

Image
Today we are gonna develop a script that will automatically delete multiple snapshots that has been taken in VMs running in the Vsphere environment. We use powercli to create the script and run over the vcenter where the VMs are hosted Before we go ahead, I would like to share you a small brief on what is powercli, powercli is a command-line interface (CLI) tool for automating vSphere and vCloud management. VMware vSphere PowerCLI debuted as the VMware Infrastructure Toolkit, also called the VI Toolkit. We have created two machine named test-vigneshbabu, test1-vigneshbabu as shown below: Now we are gonna trigger a script that will take the snapshot of these machines as “before patching” as shown below, You can customise the name of the snapshots according to your standards. Code : $servers = Get-Content "c:\vm-serverslist.txt" foreach ( $i in $servers ) {  New-Snapshot -VM $i -Name before_pathing } Note: path of the get-content is customisable and it’s the file

Changing the path policy of the SCSI lun device using Powercli in Vmware Vsphere Environment

Image
Today my motto is to change the path policy of the scsi lun from Fixed to round robin. It’s always a pain to change the path policy of the scsi lun device, it takes hours of time to change the path manually in case if we have the large environments of say 2000 ESXi and with more than 400 Devices connected with the Esxi. so we used some Powercli and create a loop to perform the redundant task well in crisp words we tried to automate this task which could save hours of manual works Code: $server = Get-content "C:\hostfile.txt" foreach ($i in $server) { Get-ScsiLun -VmHost $i -CanonicalName "naa.6006*" | where {$_.MultipathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy RoundRobin } Here in the above code I am calling the list of ESXi Host in the file named as hostfile.txt and passing it to the variable $server and this will create an array of characters over the variable $server , Each character represents Esxi hosts on devops

Rejoin a Computer to domain without Restart using powershell

Image
There are three methods to rejoin the computer to domain without restart Method 1: Test-ComputerSecureChannel -Repair -Credential (Get-Credential) When the above command is executed it will prompt for username and password and enter the domain credentials and result should show as true then the machine is re-added to domain. Method 2: netdom resetpwd /Server:DC /UserD:DomainAdmin /PasswordD:Password The above command should be executed in the command prompt under administrator prompt. Method 3: Reset-ComputerMachinePassword -Credential (Get-Credential) When the above command is executed it will prompt for username and password and enter the domain credentials and result should show as true then the machine is re-added to domain. Stay Tuned and connect with me @ Click to connect