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

import esxi image for upgrade via powercli

$
0
0

cannot find a command to import an esx image

 

any idea?Screen Shot 2018-07-06 at 11.03.39 AM.png


Generate the datastore report using powercli script send the report through email every 4 hours

$
0
0

Hi Team,

 

Could you please assist on this request. Generate the datastore report using powercli script  send the report through email every 4 hours with below condition.

 

1) datastore above 90% should highlighted with red color.

2) datastore above 70% to 90% should be highlighted with yellow color.

3) datastore below 70% should highlighted with green color.

 

Thanks

Vijay

[Script] Get stats on all Datastores as well as which VMs are running on each

$
0
0

Hi guys,

 

Just thought I would post this up here - it is a "Datastore Reporting" PowerCLI script that I have been working on in my spare time that lists all the Datastores in your vSphere environment, and gives you statistics on them - Free Space, Capacity, and an Extra that I did a VIProperty Module for - PercentFree. (You'll need LucD's awesome VIProperty module for this to run properly! - Make sure you get the latest version to get the small VIProperty I did for PercentFree too).

 

In addition to all the datastores in your environment, the script will also collect the names of VMs running on these datastores, and list them below each datastore's stats. (Templates are not supported). You will also get a column to indicate whether or not the VM is powered on. Note that this of course lists the VM name for that datastore if the VM has at least one VMDK on the datastore - so if a VM has multiple disks on various datastores, it may appear on more than one datastore

 

I got a bit of help to figure out the VM names part of this script (fetched via ExtensionData) over here from @mattboren and @LucD http://communities.vmware.com/thread/336078 - thanks for that guys

 

Here is a screenshot of the email report you'll receive:

 

http://dl.dropbox.com/u/450727/scripts/Datastore-Report/ds-report.jpg

 

And here is a link to download the all important script

 

http://dl.dropbox.com/u/450727/scripts/Datastore-Report/datastore-report.ps1

 

 

Script for those who have dropbox blocked on their firewalls etc:

 

 

# Datastore & VM Report
# By Sean Duffy (aka Shoganator on VMware Communities)
# 13/11/2011
# Uses - PowerCLI, VIProperties Module (get VIProperties from: http://www.lucd.info/viproperties/)
Import-Module VIProperty
$users = "yourmail@yourdomain.com" # List of users to email your report to (separate by comma)
$fromemail = "yourmail@yourdomain.com"
$server = "yourmailserver.com" #enter your own SMTP server DNS name / IP address here
$datastore = $null
$Report = @()
$AllDatastores = Get-Datastore | Where {$_.Name -notlike "datastore*"} | Sort Name
foreach ($datastore in $AllDatastores) {
$Report += "<TD>"
$row = "" | Select Name, FreeGB, CapacityGB, PercentFree
$row.Name = $datastore.Name
$row.FreeGB = $datastore.FreeGB
$row.CapacityGB = $datastore.CapacityGB
$row.PercentFree = $datastore.PercentFree
$Report += $row | ConvertTo-Html
#List VMs on the datastore if applicable
If ($datastore.ExtensionData.Vm.Count -gt 0){
$VMList = Get-View -Id $datastore.ExtensionData.Vm -Property Name | Select Name
$Report += "<BR></BR>"
$Report += "<B><U>VMs on this Datastore:</U></B>"
$VMTable = @()
foreach ($vm in $VMList) {
$VMContentRow = "" | Select Name, PowerState
$tmp = Get-VM $vm.Name
$VMContentRow.Name = $tmp.Name
Write-Host $tmp.Name
if ($tmp.PowerState -eq "PoweredOn") {
$VMContentRow.PowerState = $tmp.PowerState
}
else {
$VMContentRow.PowerState = $tmp.PowerState
}
$VMTable += $VMContentRow
}
$Report += $VMTable | ConvertTo-Html -Fragment
}
else {
$Report += "<BR></BR>"
$Report += "<B><U>VMs on this Datastore:</U></B>"
$Report += "<table style=""background-color: #FFCC99""><tr align=""center""><th>Name</th></tr>"
$Report += "<td align=""center"">No VMs on this Datastore</td></table>"
}
$Report += "<BR></BR>" #Line break for clarity
$Report += "</TD>"
}
$Report | Set-Content C:\DSReport.html #Also write to an HTML report on disk - with basic formatting, in addition to the email report you are sent.
# HTML formatting for email
$HTMLmessage = @"<font color=""black"" face=""Arial, Verdana"" size=""3""><u><b>Datastore Report</b></u><br></br><br></br><style type=""text/css"">body{font: .8em ""Lucida Grande"", Tahoma, Arial, Helvetica, sans-serif;}
ol{margin:0;padding: 0 1.5em;}
TABLE{border-width: 1px;border-style: solid;border-color: black;}
TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
TD{text-align:center;border-width: 1px;padding: 5px;border-style: solid;border-color: black;}
table{color:#000;background:#99CCFF;border-collapse:collapse;width:647px;border:3px solid #900;}
thead{}
thead th{padding:1em 1em .5em;border-bottom:1px dotted #FFF;font-size:120%;text-align:left;}
thead tr{}
td{padding:.5em 1em;}
tfoot{}
tfoot td{padding-bottom:1.5em;}
tfoot tr{}
#middle{background-color:#900;}</style><body BGCOLOR=""white"">
$Report</body>
"@ 
#Send the final report!
send-mailmessage -from $fromemail -to $users -subject "Datastore Report" -BodyAsHTML -body $HTMLmessage -smtpServer $server

 

I'm sure there are areas that could be improved, so please feel free to change if you like - just be sure to post back your addition's / extra functionality you have added here! Hope this helps any one looking for this kind of info in a nicely formatted E-mail report

 

Cheers,

Sean

 

Message was edited by: Shoganator - trying out better syntax highlighting.

$global:DefaultVIServers and get the result from vcenters that i didnt want

$
0
0

how possible this could happen?

the script calls upon all vcenters i have instead only vcenters i listed in the $vc

 

$vc = get-content -path C:\vcenters.txt

foreach($vcin$global:DefaultVIServers)

 

Scripts Failing Suddenly

$
0
0

I have had a number of scripts fail recently, I run the script manually and here is the script and output:

 

#############################

# Connect to vCenter        #

#############################

Start-Transcript -Path 'C:\Temp\script.log'

Import-Module -Name VMware.PowerCLI

Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false

$vc = 'DNS'

$Cred = Import-Clixml C:\util\Scripts\creds\autoitjob.xml

 

 

Connect-VIServer $VC -Credential $Cred

 

 

#############################

#         Variables         #

#############################

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\Thin-$date.htm"

 

 

#############################

#          Content          #

#############################

$report = Get-VM | Get-HardDisk | where {$_.StorageFormat -ne "Thin"} | select Parent,StorageFormat,Filename

 

 

#$report = Get-VM | Get-HardDisk |

#where {$_.StorageFormat -ne "Thin"} |

#select Parent,StorageFormat,Filename

 

#############################

# Add Text to the HTML file #

#############################

$report | ConvertTo-Html -title "VMware Thin Provision Check" -body "<H1>Vmware Thin Provision Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation

ConvertTo-Html -title "VMware Thin Provision Check" -body "<H4>Date and time </H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

ConvertTo-Html -title "VMware Thin Provision Check" -body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

 

 

######################

# FTP HTML output #

#####################

 

 

#we specify the directory where all files that we want to upload 

$Dir="$filelocation"

#Below for test

#$Dir="C:/Users/administrator/Desktop/tmp/"   

 

#ftp server

$ftp = "ftp://IP/internal-backups/datacenter/vcenter/misc-reports/Thin/"

$user = "USER"

$pass = "PW" 

 

$webclient = New-Object System.Net.WebClient

 

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 

 

#list every sql server trace file

foreach($item in (dir $Dir "*.bak")){

    "Uploading $item..."

    $uri = New-Object System.Uri($ftp+$item.Name)

    $webclient.UploadFile($uri, $item.FullName)

}

##############################

# Disconnect session from VC #

##############################

disconnect-viserver -confirm:$false

 

OUTPUT:

PS C:\util\scripts\Reports\Daily> .\ThinReport.ps1

Transcript started, output file is C:\Temp\script.log

 

 

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout

                                                                                                  Seconds

-----    -----------     ------------------- ------------------------  -------------------------- -------------------

Session  UseSystemProxy  Multiple            Ignore                    False                      300

User                     Multiple            Ignore                    False

AllUsers

 

 

IsConnected   : True

Id            : /VIServer=vsphere.local\powercli@DNS:443/

ServiceUri    : https://vcenter6.ruralnex.com/sdk

SessionSecret : "7f2930a91d58a037dd232de769e26727c3338c71"

Name          : vcenter6.ruralnex.com

Port          : 443

SessionId     : "7f2930a91d58a037dd232de769e26727c3338c71"

User          : VSPHERE.LOCAL\PowerCLI

Uid           : /VIServer=vsphere.local\powercli@vcenter6.ruralnex.com:443/

Version       : 6.5.0

Build         : 8667236

ProductLine   : vpx

InstanceUuid  : e66b929f-6e6e-4791-aafc-621177fc31b1

RefCount      : 1

ExtensionData : VMware.Vim.ServiceInstance

 

 

Get-VM : 7/9/2018 11:01:54 AM   Get-VM          Value cannot be null.

Parameter name: array

At C:\util\scripts\Reports\Daily\ThinReport.ps1:22 char:11

+ $report = Get-VM | Get-HardDisk | where {$_.StorageFormat -ne "Thin"} ...

+           ~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

 

 

Uploading C:\util\Scripts\Temp\Thin-2018-Jul-9.htm...

udp capture on esxi host for 902

$
0
0

Is it possible to capture udp traces from powershell?

Create Multiple VM snapshots with VMware PowerCLI 10

$
0
0

Hello,

 

In the earlier version of PowerCLI 6.5 creating a snapshot on multiple VMs was very straightforward.

 

Example:

1) Group VMs: $VM1 = Get-VM VM1, VM2, VM3, VM4

2) Create snapshots on group VMs: New-Snapshot -VM $VM1 -Name "Your snapshot name" -Description "Your description".

 

Since from VMware PowerCLI version 10 'VM" parameter no longer accepts an array, this is no longer possible.

Can someone write me an example that can be used with PowerCLI 10?

Powercli support for the HCX

$
0
0

Hi,

I am looking for the Powercli cmdlets if any available to manage the HCX operations.

Please help me if you are aware.

 

Thanks.


Install-VMHostPatch

$
0
0

Can this cmdlet be used to install VIB files?

Powered off VM's and how long they have been powered off by.

$
0
0

Is it possible to get a script to show the powered off VM's in a cluster ande how long they have been powered off in days.

Dept Usage Reports

$
0
0

I am looking for a way to change this script from outputting a CSV to a HTML file.

 

Script:

$folder = 'SysDev'

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\$folder-$date.htm"

 

$vms = Get-Folder $folder | Get-VM

$vms | Select-Object @{e={$_.name};L="VM Name"},

@{e={$_.NumCpu};L="vCPU's"},

@{e={$_.MemoryGB};L="RAM(GB)"},

@{n="HDD Total GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},

@{n="HDD Used GB"; e={[math]::round( $_.UsedSpaceGB )}}|

 

 

Export-Csv -Path $filelocation -NoTypeInformation

Setting the number of available ports to 0 on all port groups

$
0
0

I am currently working with a customer that does government work, and has a requirement that all portgroups have 0 ports available. When a new server is spun up, an additional port is added; when it is decommissioned the port is (theoretically) removed. However this has not been the case, and running a small script against all portgroups shows a number that have several or more open ports. I am looking for a way to drop that to 0 without having to go through each manually, but am not finding a way.

 

To see what is out there, I am just pulling info from get-virtualportgroup. $_.ExtensionData.PortKeys.Count gives me the total number of ports, $_.ExtensionData.vm.count gives me the number of ports in use, and then I am simply subtracting one from the other to get a "portsleft" variable. Is there an easy way to take that portsleft var and set it to 0?

Sending FT -Autosize output in the body of email

$
0
0

I have wrote this very fisher price script to send me a email about snapshots older than 30 days. It works, but the output looks horrible in the email. Any way to fix it? I am a beginner at this so go easy on me.

 

$Output = get-vm | Get-Snapshot | sort-object -property created| ft -property name, VM, Description, created -AutoSize | Out-string

send-mailmessage -from "gustavo.fring@bb.com" -to "gustavo.fring@bb.com" -subject "Testfrom PS" -body $Output -smtpServer "smtp.bb.org"

Connect to multiple esxi host and find all VM's with 7days old snapshots only and email to admins CSV format

$
0
0

VM's details

 

VMName, OS, VMState, VMHost IP details, ProvisionedSpaceGB, UsedSpaceGB, Datastore, Datastore Capacity, SnapshotName, SnapshotDate, SnapshotSizeGB, SnapshotCreator

 

Ta

get hostname and port details from text file

$
0
0

Hi,

 

Is there a way to get hostname and port details from one text file instead of executing the script multiple times, I am trying to ssh to linux machines (Posh-SSH)

 

New-SSHSession -ComputerName mylinux -Port 222 -Credential $credential -AcceptKey

 

New-SSHSession -ComputerName mylinux1 -Port 223 -Credential $credential -AcceptKey

 

I tried executing

 

New-SSHSession -ComputerName mylinux1:223 -Credential $credential -AcceptKey

 

I am getting the error

 

New-SSHSession : No such host is known

At line:1 char:1

+ New-SSHSession -ComputerName mylinux1:223 -Credential $credential -AcceptK ...

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

    + CategoryInfo          : InvalidOperation: (Renci.SshNet.SshClient:SshClient) [New-SSHSession], SocketException

    + FullyQualifiedErrorId : SSH.NewSshSession

 

please help


Get datastore with highest free space and VM less than 20

$
0
0

Hello,

I have been trying to get a script working where we can find a datastore with the highest free space and the number of VMs on that datastore 20 or less.  I have tried a few different things but not getting any success.  One of the many things i have tried is shown below which errors out as well.  What i am trying to accomplish here is that if the it matches the above criteria then the script will be selecting that particular Datastore to create the new VM on.  I have used the first line from this community but just added the foreach block.  Any help would be appreciated.  Thank you.

 

$ds = Get-Datastore | Select-Object -Property Name, FreespaceGB, @{Name="NumVM";Expression={$_.ExtensionData.Vm.Count}} | Sort-Object -Property freespaceGB -Descending:$true

 

foreach ($i in $ds)

{

if ($i -ge 4)

{

continue

}

}

 

Cannot compare "@{Name=ServerOperations_iSCSI_LUN00; FreeSpaceGB=274.646484375; NumVM=2}" to "4" because the objects are not the same type or the object "@{Name=ServerOperations_iSCSI_LUN00;

FreeSpaceGB=274.646484375; NumVM=2}" does not implement "IComparable".

At line:5 char:6

+  if ($i -ge 4)

+      ~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException

    + FullyQualifiedErrorId : PSObjectCompareTo

Identify Linked Clones in ESXI 6.5

$
0
0

Need help identifying linked clones in esxi 6.5 using powercli.

 

I currently have 30+ vm's that our linked clones are based off of. We use those vm's and make 800+ linked clones for testing our product.

 

I need to move the 30+ vm's to a new datastore and want to identity all the linked clones associated with those 30+ so I can remove the linked clones.

 

Any help would be much appreciated.

Export list of VMs with complete folder path

$
0
0

Hi all,

 

I´m not a scripter so I need your help for my environemnt - 1 vcenter 5 datacenters without templates.

I need an export in csv contains the BlueFolderPath, I found a lot of scripts using Get-Folder and Get-FolderPath (is not recognized as the name of a cmdlet) something like that but nothing is working.

 

example CSV:

AB
testvm1DATACENTER\Applications\Banking\external
testvm2DATACENTER\Applications\Banking
testvm3DATACENTER\
testvm4DATACENTER\Applications

 

I found a lot of scripts from LucD but I think I´m to stuipd to get it to fly.

 

Get the folderpath - LucD notes

Folder by Path - LucD notes

 

I hope someone can help me

 

Thanks a lot

Greetings

Accessing Total Provisioned Space on Datastore Summary Tab

$
0
0

I'm looking at the datastore summary tab for a datastore object in vSphere Client and I see what is on the attached screenshot.

 

I can't seem to find this property on the object in powerCLI.  (At least for purposes of this specific post) I don't want to try to calculate it myself by adding up the individual VMs but I want to try to access the exact same property using PowerCLI which is being displayed in the attached screenshot.

 

Where can I find this property?  How do I add it to this script:

 

get-datastore | select name, freespacegb, [access this property somehow here]

 

Thanks!

Find total space consumed on a datastore for a thick provisioned VM

$
0
0

I'm attempting to find the complete amount of space that will be used for a VM on a datastore. The datastore has a property called "provisioned space"  This property includes swap file space and other items that are NOT included in the provisionedspaceGB number for each individual VM.  As a result, the sum of provisionedspaceGB for all VMS is NOT equal to the provisioned space value for the whole datastore.

 

How can I find the total space for an individual thick provisioned VM including all files for that VM that will contributed to the "provisioned space" property of the datastore?

 

Thanks!

Viewing all 16717 articles
Browse latest View live


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