Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all 16717 articles
Browse latest View live

Resignature a VMFS Datastore Copy

$
0
0

anyone know of or seen a powercli script to mount a new disk/lun and "assign a new signature" on the same time?  it works well on the gui, but I'm trying to automate the process.  any help is appreciated.

 

https://docs.vmware.com/en/VMware-vSphere/5.5/com.vmware.vsphere.hostclient.doc/GUID-5A4E2248-12CB-4A10-B167-79D3D13D3751.html

 

Procedure

  1. Log in to the vSphere Client and select the server from the inventory panel.
  2. Click the Configuration tab and click Storage in the Hardware panel.
  3. Click Add Storage.
  4. Select the Disk/LUN storage type and click Next.
  5. From the list of LUNs, select the LUN that has a datastore name displayed in the VMFS Label column and click Next.   The name present in the VMFS Label column indicates that the LUN is a copy that contains a copy of an existing VMFS datastore.
  6. Under Mount Options, select Assign a New Signature and click Next.
  7. In the Ready to Complete page, review the datastore configuration information and click Finish.

XML Cred File

$
0
0

Hey all,

 

I am working on hiding my credentials using an XML file instead of having the creds directly in the script.  When I had the creds in the script it will look like the report on Nov 14th.  When I call the creds using an XML file it works inside of powercli, but when I use task scheduler it shows like the report from Nov 16th.  What am I missing??

 

here are my settings in the task scheduler:


General Tab:

     An Domain Admin Runs the Task

     Run whether user is logged on or not

     Run with highest privilages

Trigger Tab:

     Daily at 7:55

Actions Tab:

     Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

     Argument: -File "C:\util\scripts\ThinReport.ps1"

PowerCLI to list all Powered Off VMs and Date of Event

$
0
0

I am trying to get this script to work but it doesn't even seem close at this point.  I am looking to run a report on Powered Off VMs and information about them.  I need to be able to clean the environment and have to wait 60 days before I permanently delete anything.  Any help would be great.

 

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password XXXXXXXXXXXX

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password XXXXXXXXXXXX

 

$Report = @()

$VMs = get-vm |Where-object {$_.powerstate -eq "poweredoff"}

$Datastores = Get-Datastore | select Name, Id

$VMHosts = Get-VMHost | select Name, Parent

 

foreach ($vm in Get-VM){

$view = Get-View $VMs

Get-VIEvent -Entity $VMs -MaxSamples ([int]::MaxValue) |

where {$_ -is [VMware.Vim.VmPoweredOffEvent]}

Group-Object -Property {$_.Vm.Name} | %{

  $lastPO = $_.Group | Sort-Object -Property CreatedTime -Descending | Select -First 1

  $row = '' | select VMName,Powerstate,OS,Host,Cluster,Datastore,NumCPU,MemMb,DiskGb,PowerOFF

    $row.VMName = $VMs.Name

    $row.Powerstate = $VMs.Powerstate

    $row.OS = $VMs.Guest.OSFullName

    $row.Host = $VMs.host.name

    $row.Cluster = $VMs.host.Parent.Name

    $row.Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name

    $row.NumCPU = $VMs.NumCPU

    $row.MemMb = (($VMs.MemoryMB),2)

    $row.DiskGb = ((($VMs.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)

    $row.PowerOFF = $lastPO.CreatedTime

  $report += $row

}}

$report | Sort Name | Export-Csv -Path "C:\XXXXX\Powered_Off_VMs.csv"

disconnect-viserver * -confirm:$false

 

I don't get an export to CSV and a display on screen of the following:

 

Template             : False

Key                  : 165369

ChainId              : 165369

CreatedTime          : 6/28/2016 10:19:35 AM

UserName             :

Datacenter           : VMware.Vim.DatacenterEventArgument

ComputeResource      : VMware.Vim.ComputeResourceEventArgument

Host                 : VMware.Vim.HostEventArgument

Vm                   : VMware.Vim.VmEventArgument

Ds                   :

Net                  :

Dvs                  :

FullFormattedMessage : ServerName on  XXX-prodesxi-10.xxxxx.com in ClusterName is powered off

ChangeTag            :

How to install latest PowerCLI in a server that has no internet connection ?

$
0
0

Hi,

 

I would like to be able to install the latest PowerCLi on a windows server that has no internet connection.

I tried it by running

Install-Module -Name VMware.PowerCLI

And then copying the files to the server that has no internet connection.

After installing powershell 5 on it, it requests also the nuget cmdlets.... and ... for that it needs internet connections....

This is a hassle... and doesn't make it attractive to use the latest version.

 

So what is the easiest way to  install the latest PowerCLi on a system that has no internet connection ?

New-VMHostNetwork Adapter no option to enable provisioning?

phisical nic _vlan_info_powercli

$
0
0

Hello Luc/all,

 

i have one standard switch info stored in variable in $s

 

 

if i do $s.nic it gave me me two physical nic

 

can yu please tell me how to get what vlans are allowed on these physical nics using powercli.

Command to tell what vCenter you are connected to

$
0
0

Is there a PowerCLI command to display which vCenter(s) you are connected to?

esxi build vs vcenter build_powercli

$
0
0

Hi Luc,

 

could you suggest if there is any recommendation in terms of  maintaing esxi build as per the build of vcenter .

its not powercli question but since i found info using powercli so thought of asking powercli community.

 

following  are different builds (of version 5.5) of esxi and vcenter build is 5.5u3a.  

vmware tech support once suggested to have 3116895 for vcenter 5.5u3a.

 

 

get-vmhost|group-object -property build.

 

 


Export DRS Rules to csv for documentation purposes

$
0
0

I needed something to make DRS rule documentation easier so I did this:

 

# Export DRS Rules to CSV

# Requires PowerCLI 6.5.1+

 

# Export DRS Rules

Get-Cluster | Get-DRSRule | select Name,Cluster,Enabled,Type,@{N='VMs';E={[string]::Join(',',((Get-VM -ID $_.VMIDs).Name))}} | Export-CSV -NoType -Delimiter ';' -Encoding Default DRSRule.csv

 

# Export DRSClusterGroup

Get-Cluster | Get-DRSClusterGroup | Select Name,Cluster,Grouptype,@{N="Member";E={[string]::Join(',',($_.Member))}} | Export-CSV -NoType -Delimiter ';' -Encoding Default DRSClusterGroup.csv

 

# Export DRSVMHostRule

Get-Cluster | Get-DRSVMHostRule | Select Name,Cluster,VMGroup,Type,VMHostGroup,Enabled | Export-CSV -NoType -Delimiter ';' -Encoding Default DRSVMHostRule.csv

 

Somebody might find this useful.

PowerCLI to modify firewall policy for allowed ip's

$
0
0

I need to change the ESXi firewall setting from Allow connections from any IP address to a list of networks.

 

Using the get-esxcli cmdlet I can set the ip's to use.

 

(Get-VMHost $esxhost )
$esxcli = Get-EsxCli -VMHost $esxhost

$esxcli.network.firewall.ruleset.allowedip.add("172.16.29.0/24", "sshServer")

 

The issue I have is that to run the above, I first need to go into vcenter and manually change the firewall setting from all ip's to only these ip's.

 

When I set my $esxcli and run: $esxcli.network.firewall.ruleset.set

 

this is the output:

 

TypeNameOfValue     : VMware.VimAutomation.ViCore.Util10Ps.EsxCliExtensionMethod

OverloadDefinitions : {boolean set(boolean allowedall, boolean enabled, string rulesetid)}

MemberType          : CodeMethod

Value               : boolean set(boolean allowedall, boolean enabled, string rulesetid)

Name                : set

IsInstance          : True

 

I think its possible to change the allowed all to disabled, but I can't figure out what they mean by this set(boolean allowedall, boolean enabled, string rulesetid).  I understand that the string rulesetid is sshServer, but what do they mean with boolean allowedall ?

 

Has anyone ever done this before ?

Cleanup PowerCLI 6.5.x old directories after update-module ?

$
0
0

I noticed that when I update-module PowerCLI the old versions aren't removed.

 

Is there a way to cleanup this ? i.e. automatically remove the old module versions ?

 

Of course I can do this manually but hey we are automating stuff here

VMs Disk Usage Report

$
0
0

I got a script that work but want to include a subtotal for each VM and not sure how to insert/add a subtotal line at end of each VM.  The output report will be in CSV.

 

Any help will be greatly appreciated.

 

$FinalResult = @() 

$ALLvms = Get-View -ViewType "VirtualMachine"

$allvms | foreach-object {

       $vm = $_

       $vmname = $vm.name

       $Drives = $vm.Guest.Disk

       $drives  | foreach-object {

            $driveC = $_

            $object = New-Object -TypeName PSObject

            $Capacity = "{0:N0}" -f [math]::Round($DriveC.Capacity / 1MB) 

            $Freespace = "{0:N0}" -f [math]::Round($DriveC.FreeSpace / 1MB)

            $Percent = [math]::Round(($FreeSpace)/ ($Capacity) * 100)

            $PercentFree = "{0:P0}" -f ($Percent/100)

            $object | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $vmname

            $object | Add-Member -MemberType NoteProperty -Name Disk -Value $Drivec.DiskPath

            $object | Add-Member -MemberType NoteProperty -Name "Capacity MB" -Value $Capacity

            $object | Add-Member -MemberType NoteProperty -Name "Free MB" -Value $FreeSpace

            $object | Add-Member -MemberType NoteProperty -Name "Free %" -Value $PercentFree

            $finalResult += $object

        }  

    }

$finalResult | Export-Csv "C:\DiskUsageReport.csv" -NoTypeInformation  -UseCulture    # dump the report to .csv

vMotion TCP/IP Netstack - gateway

$
0
0

Can anyone help me figure out how to set this value from powercli or esxcli?

 

gateway.jpg

Erase VSAN Partitions via Powercli

$
0
0

Hi All,

 

Rebuilding some previously used VSAN nodes however to reclaim the disks for a new VSAN cluster I either need to erase the partitions on each of the disk via the GUI (See Screenshot)

 

Or Enable VSAN on the cluster and delete diskgroups and recreate.

 

I was hoping there was a method I could erase the partition via Powercli?

License Failure and DVUplink False Positive Error

$
0
0

I am getting a couple of errors I was hoping to get some opinions on.

 

License Section:

In my script I get an entityId error when the licensing section runs, but if I try this same syntax without the variables by typing directly into the PS window - it executes fine.

 

foreach ($vmhost in $vmhost_array) {
Write-Host "Adding New Host - " $vmhost "to vCenter..."
Add-VMHost $vmhost -Location $cluster -User $user -Password $passwd -RunAsync -force:$true | Out-Null

Write-Host "Adding License to New Host - " $vmhost "..."
Set-VMHost -VMHost $vmhost -LicenseKey $esx_license | Out-Null
}

 

Set-VMHost : 11/18/2017 5:56:54 PM      Set-VMHost              A specified parameter was not correct: entityId

At C:\Documents\PowerCLI\Config.ps1:24 char:1

+ Set-VMHost -VMHost $vmhost -LicenseKey $esx_license | Out-Null

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Set-VMHost], InvalidArgument

    + FullyQualifiedErrorId : ViCore_ComputeResourceServiceImpl_UpdateHostLicense_ServerError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVMHost

 

DVUplink Section:

I get the error for this section of the script but it actually configures the port groups as expected.  I have also noticed that if a DVSwitch is created via GUI the uplinks are named "Uplink 1" and "Uplink 2" respectively but if the DVSwitch is created via PowerCLI then the uplinks are named "dvUplink1" and "dvUplink2" respectively.  Any thoughts on whats causing the false positive? Or is it even a false positive?

 

Write-Host "Creating vMotion Port Group for" $vds_name "..."
New-VDPortgroup -VDSwitch $vds_name -Name $esx_vmotion_PG -VlanId 6 | Out-Null

Write-Host "Setting vMotion Port Group Teaming Policy..."
Get-VDPortgroup $esx_vmotion_PG | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort "dvUplink1" -StandbyUplinkPort "dvUplink2" -UnusedUplinkPort "dvUplink3","dvUplink4" -LoadBalancingPolicy ExplicitFailover | Out-Null

 

Set-VDUplinkTeamingPolicy : 11/18/2017 5:57:35 PM       Set-VDUplinkTeamingPolicy               A specified parameter was not correct: spec.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort. The activeUplink

PortName value :

dvUplink1 is not valid in the spec.uplinkTeamingPolicy.uplinkPortOrder.activeUplinkPort.

At C:\Documents\PowerCLI\Config.ps1:51 char:64

+ ... ingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort "dvUplink1" - ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Set-VDUplinkTeamingPolicy], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.Vds.Commands.Cmdlets.SetVDUplinkTeamingPolicy


Powercli running Invoke-VMScript and Diskpart.exe against hangs

$
0
0

I am attempting to run a PowerCLI script to extend the Citrix D drive (WCDisk) 200+ VDI machines.  Running the script in PowerCLI on a test machine works fine up until it hits the Invoke-VMScript calling Diskpart.exe. It just hangs.  I think I've determined when attempting to call Invoke-VMScript to run diskpart to extend D drive (WCDisk) within the VDI OS UAC is blocking it from running because it just hangs…See screen shot below.

 

Also, from within the VDI that the script is running against, I can see the Diskpart.exe CMD process just sitting there in TaskMgr.

 

 

Here is the test script I am running..

 

$HostCredential = Get-Credential

$GuestCredential = Get-Credential

#This part hangs

Invoke-VMScript -HostCredential $HostCredential -vm Win10Test6 -GuestCredential $GuestCredential -ScriptText "C:\windows\system32\diskpart.exe /s c:\Windows\temp\diskpart.txt" -ScriptType BAT   *** This stalls out ***

 

If I substitute the Diskpart commands for a non-interactive command such as 'dir' the process runs without issue. This tells me the process and my userid is not the issue.

 

This one works just fine so I know my userid is correct..

 

#Invoke-VMScript -HostCredential $HostCredential -vm Win10Test6 -GuestCredential $GuestCredential -ScriptText "dir" *** Worked

 

NOTE:

•        I ‘think’ UAC might be causing an issue but that is a hunch. I’ve tried to disable UAC but that takes a reboot to set the value and truly be disabled.  This is a Citrix PVS env and UAC is on and the VDI machines reboot to a known state (UAC on).  I haven't gone as far as creating another image with UAC off to test.

 

 

Questions I need help with are:

  1. Is there a better or easier way to extend a drive via PS with UAC on?
  2. Is there a way to bypass UAC with use of Enter-PSSession running the same commands elevated?

Assign vminc to Specific Uplink on VDS

$
0
0

Hi All,

 

I have requirement to assign vminic1 to Uplink 2 on my VDS.. vminic0 is assigned to VSS vSwitch0 and before migrating VMkernels to the VDS (via Powershell) I need to have an active Uplink on it. When assigning the vminc1 to the VDS it defaults to Uplink 1 is there anyway to specify Uplink 2.

 

My current work around in my script is to add the vminc1 to VSS, set active Nic Team as active for both vmnics then move vmnic0 to VDS?

security_profile_esxi_powercli

$
0
0

Hello Luc,

 

there is a requirement to stop unwanted services in esxi secuirtyprofile.

 

following is what i got from of the esxihost using $esx_cli.network.firewall.ruleset.list()

 

 

can yu suggest what is the default settings as i have not  seen enabling any other service except ssh server.

Loop Help and TCP/IP Stack

$
0
0

I'm running an Import-Csv on a csv file that holds all the vmk IP information for each vmk to be created.  I was hoping to loop through the information and to set all the IPs and it works but I'm getting errors.  It seems like the loops is trying to go back through twice.

 

$csv = Import-Csv C:\vmk_create_vds2.csv -UseCulture | %{

foreach ($line in $csv){
Write-Host "Creating vMotion VMKernel Port for" $_.Host"..."
New-VMHostNetworkAdapter -VMHost $_.Host -VirtualSwitch "vds-01" -PortGroup $_.vMoPG -IP $_.vMoIP -SubnetMask $_.vMoMask -Mtu 9000 -VMotionEnabled:$true -Confirm:$false | Out-Null
Write-Host "Creating NFS VMKernel Port for" $_.Host"..."
New-VMHostNetworkAdapter -VMHost $_.Host -VirtualSwitch "vds-01" -PortGroup $_.NFSPG -IP $_.NFSIP -SubnetMask $_.NFSMask -Mtu 9000 -Confirm:$false | Out-Null
Write-Host "Creating FT VMKernel Port for" $_.Host"..."
New-VMHostNetworkAdapter -VMHost $_.Host -VirtualSwitch "vds-01" -PortGroup $_.FTPG -IP $_.FTIP -SubnetMask $_.FTMask -Mtu 9000 -FaultToleranceLoggingEnabled:$true -Confirm:$false | Out-Null
}
}
Write-Host "***VMKernelConfiguration Section Complete***"

 

CSV Data:

           

HostdvSwitchvMoPGvMoIPvMoMaskNFSPGNFSIPNFSMaskFTPGFTIPFTMask
host01vds-01esx_vmotion3.3.3.1255.255.255.0esx_nfs1.1.1.1255.255.255.0esx_ft2.2.2.1255.255.255.0
host02vds-01esx_vmotion3.3.3.2255.255.255.0esx_nfs1.1.1.2255.255.255.0esx_ft2.2.2.2255.255.255.0

 

 

Also, I've tried enabling TCP/IP for vmotion in this by using the other posts related to the topic, but I can't wrap my head around where it fits in my vmkernel section.  I only need to enable it and use the default gateway that is already set on the adapter so that it can be used later without creating a new vmk port.

Creating a folder in a cluster

$
0
0

I apologize for the very basic question.

I have a datacenter whose nema is, let's say, "MyDatacenter" and a cluster inside the datacenter whose name in "MyCluster".

How can I create a folder whose nami ins "Folder1" in "MyCluster" so that I can see:

 

MyDatacenter

     MyCluster

          Folder1

          Folder2

               Subfolder2_1

          Folder3

 

Up to now I was unable to get the right syntax...

Regards

marius

Viewing all 16717 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>