SlideShare a Scribd company logo
Chris Halverson
Why use PowerCLI
 The biggest question to ask is:
 Why would I use PowerShell (PoSH) if there
is a perfectly good Graphical User Interface?
 When there is Administration of Multiple
systems there is always a need for
scripting.
 Basic Example:
○ Get a list of all VM, just by their names
Script and Output
Get-VM | select Name
Name
====
Server1
Server2
Server3
Server4
Server5
Server6
Server7
…
Real World Scenario
 Joe is an Administrator at a small Oil
and Gas company that has 4 ESXi
servers and 120 VMs running on them.
 Joe’s manager requests a report for a
list of Servers in the environment, with
the amount of CPUs, Memory, Disk
Space used.
 “Piece of Cake” Joe says as he goes to
the VIClient to pull a report from the
GUI.
Using the GUI
 Joe selects Inventory 
Hosts and Clusters,
Selects the vCenter host
and then selects the
“Virtual Machines” Tab.
 He sorts the Virtual
Machines by name and
examines what fields are
able to be displayed.
Shortcomings of Using the GUI
 Joe assesses that using the GUI can be
done but he knows his manager and he
will ask for this report again, and again,
and again, and he would like to either
automate this or have this running via a
single script.
 Joe also wants to exclude certain
servers as they are test machines and
are not needed for this report for his
manager. (Names Start with Test)
Attempting the first script
Needs:
Name, vCPUs, Memory and Disk Used
Script:
Get-VM | Select Name, NumCPU, MemoryGB,
UsedDiskGB
First Script Output
Output:
Name NumCPU MemoryGB UsedDiskGB
==== ====== ======== ==========
Server1 2 4.0000008 31.0103883
Server2 4 7.999293 48
TestServer1 1 1.9199201 48
 As you can see the script produced the
results we were looking for, however with
some mixed output results, and what about
the exclusion of Test machines.
First Script Revamp
Script:
Get-VM | Select Name, NumCPU,
@{Name=“Memory”;Expression={[System.Math]::Round(
$_.MemoryGB, 2)}}, UsedSpaceGB
Explanation:
 Okay, this looks complicated but when you break it down it is
very similar to the first attempt, but we are naming the
MemoryGB – “Memory” and using a system method using a
Math Function to Round the variable to 2 decimal points.
 We could also do this to the UsedSpaceGB to make it easier
to read.
First Script Revamp Output
Output:
Name NumCPU Memory UsedDiskGB
==== ====== ======== ==========
Server1 2 4 31.0103883
Server2 4 7.99 48
TestServer1 1 1.91 48
 As you can see the script produced the
results we were looking for, however with
some mixed output results, and what about
the exclusion of Test machines.
First Script Revamp (part 2)
Script:
Get-VM | where{$_.Name –notmatch “Test”} | Select
Name, NumCPU, @{Name=“Memory”; Expression=
{[System.Math]::Round($_.MemoryGB, 2)}},
@{Name=“Used Disk”; Expression=
{[int]$_.UsedSpaceGB}}
Explanation:
 We added two additional components to this one
 First to remove the VMs with the name Test within it.
 Second to format the usedSpaceGB to a number with no decimal places.
Script Revamp Output (2)
Output:
Name NumCPU Memory Used Disk
==== ====== ======== ==========
Server1 2 4 31
Server2 4 7.99 48
Notice the formatting is good
the test server is removed
balance to the force has been restored.
Now for Something Useful
 Who has to deal with aging snapshots
when other administrators in your group
think that a snapshot is a backup?
 Your datastores show a red exclamation
mark and seem to be almost full???
 Script:
The easiest would be to blanket remove all the
snapshots via this script
Get-VM | Get-Snapshot | Remove-Snapshot
Snapshot Script
 The problem with this is that it may take
DAYS to reconcile the snapshots and you
want to see how bad the damage is before
you run this.
 So you run a variation on the original script
to firstly produce a list and size of the
snapshots and secondly limit the scope of
reconciliation.
Get-VM | Get-Snapshot | Where {$_.SizeGB -lt 1 -and
$_.Created.Day -lt (Get-Date).Day}
Snapshot Script Output
Script:
Get-VM | Get-Snapshot | Where {$_.SizeGB -lt 1 -and
$_.Created.Day -lt (Get-Date).Day}
Output:
Name Description PowerState
---- ----------- ----------
Test PoweredOff
 Here is an example of the typical output from that
script. You can pull the information about the
Snapshot by adding a “| fl *” after it. This
displays all the information available (fl is an alias
for Format-List)
Where to go next
 I started by using Powershell.exe as my
main command line interpreter, instead of
cmd.exe.
 I also tried to use the command line
wherever possible to ensure memory of the
commands
 Document your findings!
 Maintain a script repository with specific
naming. Native commands use Get, New
and Set, consider using different verbs to
differentiate your scripts (Do, Put, or
Change)
Questions?
Where do YOU want to go next?
1 Liners Link
http://darusintegration.blogspot.ca/2011/11
/quick-and-easy-powershell-one-
liners.html

More Related Content

What's hot

Как PostgreSQL работает с диском
Как PostgreSQL работает с дискомКак PostgreSQL работает с диском
Как PostgreSQL работает с диском
PostgreSQL-Consulting
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools
Ceph Community
 
GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
Alexey Lesovsky
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
Denish Patel
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
PgDay.Seoul
 
Managing PostgreSQL with PgCenter
Managing PostgreSQL with PgCenterManaging PostgreSQL with PgCenter
Managing PostgreSQL with PgCenter
Alexey Lesovsky
 
Backup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-VBackup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-V
Ashwin Pawar
 
(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...
(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...
(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...
Amazon Web Services
 
Building images from dockerfiles
Building images from dockerfilesBuilding images from dockerfiles
Building images from dockerfiles
dotCloud
 
Rubinius 1.0 and more!
Rubinius 1.0 and more!Rubinius 1.0 and more!
Rubinius 1.0 and more!
evanphx
 
Huge pages
Huge pagesHuge pages
Huge pages
Mohsen B
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Ontico
 
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
Ontico
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
Machine learning 2 - Neural Networks
Machine learning 2 - Neural NetworksMachine learning 2 - Neural Networks
Machine learning 2 - Neural Networks
Empatika
 
Machine Learning - Introduction
Machine Learning - IntroductionMachine Learning - Introduction
Machine Learning - Introduction
Empatika
 
Building cloud stack at scale
Building cloud stack at scaleBuilding cloud stack at scale
Building cloud stack at scale
ShapeBlue
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
Reuven Lerner
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
Ontico
 

What's hot (19)

Как PostgreSQL работает с диском
Как PostgreSQL работает с дискомКак PostgreSQL работает с диском
Как PostgreSQL работает с диском
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools
 
GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
 
Managing PostgreSQL with PgCenter
Managing PostgreSQL with PgCenterManaging PostgreSQL with PgCenter
Managing PostgreSQL with PgCenter
 
Backup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-VBackup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-V
 
(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...
(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...
(PFC303) Milliseconds Matter: Design, Deploy, and Operate Your Application fo...
 
Building images from dockerfiles
Building images from dockerfilesBuilding images from dockerfiles
Building images from dockerfiles
 
Rubinius 1.0 and more!
Rubinius 1.0 and more!Rubinius 1.0 and more!
Rubinius 1.0 and more!
 
Huge pages
Huge pagesHuge pages
Huge pages
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
 
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Machine learning 2 - Neural Networks
Machine learning 2 - Neural NetworksMachine learning 2 - Neural Networks
Machine learning 2 - Neural Networks
 
Machine Learning - Introduction
Machine Learning - IntroductionMachine Learning - Introduction
Machine Learning - Introduction
 
Building cloud stack at scale
Building cloud stack at scaleBuilding cloud stack at scale
Building cloud stack at scale
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
 

Viewers also liked

Power Cli Workshop London Vmug
Power Cli Workshop London VmugPower Cli Workshop London Vmug
Power Cli Workshop London Vmug
jonathanmedd
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
June Blender
 
Automation using power cli
Automation using power cliAutomation using power cli
Automation using power cli
esarakaitis
 
PowerShell Technical Overview
PowerShell Technical OverviewPowerShell Technical Overview
PowerShell Technical Overview
allandcp
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
Fahad Noaman
 
Covmug v sphere 4.1 what's new
Covmug v sphere 4.1 what's newCovmug v sphere 4.1 what's new
Covmug v sphere 4.1 what's new
esarakaitis
 

Viewers also liked (6)

Power Cli Workshop London Vmug
Power Cli Workshop London VmugPower Cli Workshop London Vmug
Power Cli Workshop London Vmug
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
Automation using power cli
Automation using power cliAutomation using power cli
Automation using power cli
 
PowerShell Technical Overview
PowerShell Technical OverviewPowerShell Technical Overview
PowerShell Technical Overview
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
Covmug v sphere 4.1 what's new
Covmug v sphere 4.1 what's newCovmug v sphere 4.1 what's new
Covmug v sphere 4.1 what's new
 

Similar to Where to start with power cli

SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
Amazon Web Services
 
Deep Dive on Amazon EC2
Deep Dive on Amazon EC2Deep Dive on Amazon EC2
Deep Dive on Amazon EC2
Amazon Web Services
 
CMP301_Deep Dive on Amazon EC2 Instances
CMP301_Deep Dive on Amazon EC2 InstancesCMP301_Deep Dive on Amazon EC2 Instances
CMP301_Deep Dive on Amazon EC2 Instances
Amazon Web Services
 
Deep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instancesDeep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instances
Amazon Web Services
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
Amazon Web Services
 
AutoScaling and Drupal
AutoScaling and DrupalAutoScaling and Drupal
AutoScaling and Drupal
Promet Source
 
Deep Dive on Amazon EC2
Deep Dive on Amazon EC2Deep Dive on Amazon EC2
Deep Dive on Amazon EC2
Amazon Web Services
 
Powervc upgrade from_1.3.0.2_to_1.3.2.0
Powervc upgrade from_1.3.0.2_to_1.3.2.0Powervc upgrade from_1.3.0.2_to_1.3.2.0
Powervc upgrade from_1.3.0.2_to_1.3.2.0
Gobinath Panchavarnam
 
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Rahul Krishna Upadhyaya
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
aadi Surve
 
Rally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetupRally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetup
Ananth Padmanabhan
 
AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...
AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...
AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...
Amazon Web Services
 
Exch2007 sp1 win2008
Exch2007 sp1 win2008Exch2007 sp1 win2008
Exch2007 sp1 win2008
Ziemek Borowski
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
nam kwangjin
 
AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...
AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...
AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...
Amazon Web Services
 
Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)
Julien SIMON
 
VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms
VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms
VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms
VMworld
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
Amazon Web Services
 
Live deployment, ci, drupal
Live deployment, ci, drupalLive deployment, ci, drupal
Live deployment, ci, drupal
Andrii Podanenko
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
Kenny Gryp
 

Similar to Where to start with power cli (20)

SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
Deep Dive on Amazon EC2
Deep Dive on Amazon EC2Deep Dive on Amazon EC2
Deep Dive on Amazon EC2
 
CMP301_Deep Dive on Amazon EC2 Instances
CMP301_Deep Dive on Amazon EC2 InstancesCMP301_Deep Dive on Amazon EC2 Instances
CMP301_Deep Dive on Amazon EC2 Instances
 
Deep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instancesDeep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instances
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
AutoScaling and Drupal
AutoScaling and DrupalAutoScaling and Drupal
AutoScaling and Drupal
 
Deep Dive on Amazon EC2
Deep Dive on Amazon EC2Deep Dive on Amazon EC2
Deep Dive on Amazon EC2
 
Powervc upgrade from_1.3.0.2_to_1.3.2.0
Powervc upgrade from_1.3.0.2_to_1.3.2.0Powervc upgrade from_1.3.0.2_to_1.3.2.0
Powervc upgrade from_1.3.0.2_to_1.3.2.0
 
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
Rally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetupRally - Benchmarking_as_a_service - Openstack meetup
Rally - Benchmarking_as_a_service - Openstack meetup
 
AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...
AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...
AWS re:Invent 2016: Deep Dive on Amazon EC2 Instances, Featuring Performance ...
 
Exch2007 sp1 win2008
Exch2007 sp1 win2008Exch2007 sp1 win2008
Exch2007 sp1 win2008
 
Memcached Study
Memcached StudyMemcached Study
Memcached Study
 
AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...
AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...
AWS re:Invent 2016: [JK REPEAT] Deep Dive on Amazon EC2 Instances, Featuring ...
 
Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)Deep Dive on Amazon EC2 Instances (March 2017)
Deep Dive on Amazon EC2 Instances (March 2017)
 
VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms
VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms
VMworld 2013: Virtualizing and Tuning Large Scale Java Platforms
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
Live deployment, ci, drupal
Live deployment, ci, drupalLive deployment, ci, drupal
Live deployment, ci, drupal
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
 

Recently uploaded

GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
Fwdays
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
Sunil Jagani
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
leebarnesutopia
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
DianaGray10
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
ScyllaDB
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)
HarpalGohil4
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
AlexanderRichford
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
Ortus Solutions, Corp
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 

Recently uploaded (20)

GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 

Where to start with power cli

  • 2. Why use PowerCLI  The biggest question to ask is:  Why would I use PowerShell (PoSH) if there is a perfectly good Graphical User Interface?  When there is Administration of Multiple systems there is always a need for scripting.  Basic Example: ○ Get a list of all VM, just by their names
  • 3. Script and Output Get-VM | select Name Name ==== Server1 Server2 Server3 Server4 Server5 Server6 Server7 …
  • 4. Real World Scenario  Joe is an Administrator at a small Oil and Gas company that has 4 ESXi servers and 120 VMs running on them.  Joe’s manager requests a report for a list of Servers in the environment, with the amount of CPUs, Memory, Disk Space used.  “Piece of Cake” Joe says as he goes to the VIClient to pull a report from the GUI.
  • 5. Using the GUI  Joe selects Inventory  Hosts and Clusters, Selects the vCenter host and then selects the “Virtual Machines” Tab.  He sorts the Virtual Machines by name and examines what fields are able to be displayed.
  • 6. Shortcomings of Using the GUI  Joe assesses that using the GUI can be done but he knows his manager and he will ask for this report again, and again, and again, and he would like to either automate this or have this running via a single script.  Joe also wants to exclude certain servers as they are test machines and are not needed for this report for his manager. (Names Start with Test)
  • 7. Attempting the first script Needs: Name, vCPUs, Memory and Disk Used Script: Get-VM | Select Name, NumCPU, MemoryGB, UsedDiskGB
  • 8. First Script Output Output: Name NumCPU MemoryGB UsedDiskGB ==== ====== ======== ========== Server1 2 4.0000008 31.0103883 Server2 4 7.999293 48 TestServer1 1 1.9199201 48  As you can see the script produced the results we were looking for, however with some mixed output results, and what about the exclusion of Test machines.
  • 9. First Script Revamp Script: Get-VM | Select Name, NumCPU, @{Name=“Memory”;Expression={[System.Math]::Round( $_.MemoryGB, 2)}}, UsedSpaceGB Explanation:  Okay, this looks complicated but when you break it down it is very similar to the first attempt, but we are naming the MemoryGB – “Memory” and using a system method using a Math Function to Round the variable to 2 decimal points.  We could also do this to the UsedSpaceGB to make it easier to read.
  • 10. First Script Revamp Output Output: Name NumCPU Memory UsedDiskGB ==== ====== ======== ========== Server1 2 4 31.0103883 Server2 4 7.99 48 TestServer1 1 1.91 48  As you can see the script produced the results we were looking for, however with some mixed output results, and what about the exclusion of Test machines.
  • 11. First Script Revamp (part 2) Script: Get-VM | where{$_.Name –notmatch “Test”} | Select Name, NumCPU, @{Name=“Memory”; Expression= {[System.Math]::Round($_.MemoryGB, 2)}}, @{Name=“Used Disk”; Expression= {[int]$_.UsedSpaceGB}} Explanation:  We added two additional components to this one  First to remove the VMs with the name Test within it.  Second to format the usedSpaceGB to a number with no decimal places.
  • 12. Script Revamp Output (2) Output: Name NumCPU Memory Used Disk ==== ====== ======== ========== Server1 2 4 31 Server2 4 7.99 48 Notice the formatting is good the test server is removed balance to the force has been restored.
  • 13. Now for Something Useful  Who has to deal with aging snapshots when other administrators in your group think that a snapshot is a backup?  Your datastores show a red exclamation mark and seem to be almost full???  Script: The easiest would be to blanket remove all the snapshots via this script Get-VM | Get-Snapshot | Remove-Snapshot
  • 14. Snapshot Script  The problem with this is that it may take DAYS to reconcile the snapshots and you want to see how bad the damage is before you run this.  So you run a variation on the original script to firstly produce a list and size of the snapshots and secondly limit the scope of reconciliation. Get-VM | Get-Snapshot | Where {$_.SizeGB -lt 1 -and $_.Created.Day -lt (Get-Date).Day}
  • 15. Snapshot Script Output Script: Get-VM | Get-Snapshot | Where {$_.SizeGB -lt 1 -and $_.Created.Day -lt (Get-Date).Day} Output: Name Description PowerState ---- ----------- ---------- Test PoweredOff  Here is an example of the typical output from that script. You can pull the information about the Snapshot by adding a “| fl *” after it. This displays all the information available (fl is an alias for Format-List)
  • 16. Where to go next  I started by using Powershell.exe as my main command line interpreter, instead of cmd.exe.  I also tried to use the command line wherever possible to ensure memory of the commands  Document your findings!  Maintain a script repository with specific naming. Native commands use Get, New and Set, consider using different verbs to differentiate your scripts (Do, Put, or Change)
  • 17. Questions? Where do YOU want to go next? 1 Liners Link http://darusintegration.blogspot.ca/2011/11 /quick-and-easy-powershell-one- liners.html