Add disk

PowerShell Code Powershell code to add disk to a Remote Windows Server VMware VM #The Following code shows how to add a New Drive, bring drive online, initialize and format: #Connect to vCenter Connect-VIServer vcsa.domain.org #Add new drive to VM New-HardDisk -VM $VMNAME -CapacityGB $DISKSIZEGB -StorageFormat Thin -Controller ‘SCSI Controller 1’ #Make disk online invoke-command -computername $VMNAME -scriptblock {Set-Disk 2 -isOffline $false} #Initialize disk invoke-command -computername $VMNAME -scriptblock {Initialize-Disk 2 -PartitionStyle GPT} #Create Partition invoke-command -computername $VMNAME -scriptblock {New-Partition -DiskNumber 2 -UseMaximumSize -DriveLetter E} #Format drive invoke-command -computername $VMNAME -scriptblock {Format-Volume -DriveLetter E -FileSystem NTFS -NewFileSystemLabel ‘Data’ -AllocationUnitSize 16384 -Confirm:$false} #------------------------------------------------------------------------- #The Following Code will show disk “Allocation Unit Size” on a remote Windows Server: $C = Invoke-Command -ComputerName $VMname {Get-WmiObject -Class Win32_Volume -Filter “DriveLetter = ‘C:'” | Select-Object BLOCKSIZE} $C_AllocationUnitSize = ($C.

Continue reading

PowerShell Code There are two PowerCLI commands that have become my best friends in a Zero Trust Environment. Invoke-VMScript - Use to run scripts on VMs. Copy-VMGuestFile - Use to copy files to/from VMs. In this example you can use Invoke-VMScript to run commands on a VM to install Trend Deep Security. All commands run with VM in a zero trust state. $VMName = 'VM Name' #Copy file to the VM $PSText = 'wget https://server01.

Continue reading

PowerShell Code I use this code to create a log file during a VM build using vRealize Automation Here’s an example: $VMname = 'ServerName' #The next line defines where to save the log file $LOGFILENAME = "C:\vRA-Install-Logs\vRA-Install-Log-" + $VMname + ".log" #Check to see if file already exists. If it does delete it. if (Test-Path $LOGFILENAME) { Remove-Item -Path $LOGFILENAME } #Creates the Log File New-Item $LOGFILENAME -ItemType File #Update Log File.

Continue reading

Randon Password

PowerShell Code I use this code to generate a random password during the automation process of creating a new Server VM. I then add the password to Password Manager with Powershell. #Generate Random text to use for Password $SQLPassword =@( [char[]](65..91 | Get-Random -Count 5) [char[]](97..123 | Get-Random -Count 5) '!','#','(',')' | Get-Random -Count 2 0..9 | Get-Random -Count 4 ) | Sort-Object {Get-Random} $Password = $SQLPassword -join ''

Continue reading

Author's picture

Dale Hassinger

Sharing Content with the vCommunity and anyone else that finds my content interesting…

Lead Systems Engineer - SME

Dillsburg, PA