SlideShare a Scribd company logo
1 of 58
A Sunil Phani’s take on Windows powershell
Windows powershell- course
-

Why should we care?
What powershell is?
Securing the shell
File and folder management
Command line tips , tricks & gotchs
Windows powershell- course
- Cmdlets, snapins, aliases ,help
- Basic cmdlets : processes , services, & event logs
- Retriving mgmt info from Remote computers (WMI)
Windows powershell- course
-

using variables ,objects , & Members
Understanding pipeline
Math & comparison operators
Sorting, measuring, selecting & filtering
Working with collection of objects
Windows powershell- course
- Formatting subsystem
- Exporting, converting, importing & comparing
- Managing active directory(and local), users, groups
etc,.
- Windows powershell scripts
Windows powershell- course
-

The scripting language (with just 14 key words)
Script blocks & functions
Custom blocks in functions
Err or trapping & handling
Script debugging
Regular expressions
Windows powershell- intro
•
•
•
•

The old way vs new way
An administrative engine
Existing and up coming products
Customizing shell
Windows powershell- intro
• Interim (phase 1)

C.E.C
Snap in

T-SQL

GUI (MMC)
Service

Product
( eg. SQL 2005)
exe

data
PSH

Config
Windows powershell- intro
• New way (Phase 2)
CLI

Scripts

GUI

Powershell
Product
( eg. Ex change 2007 )
Windows powershell- intro
• Old way

C.E.C
Snap in
GUI (MMC)
Service
Product
( eg. Ex change )
exe
Bat

WMI

data
COM

VBS

Config
Windows powershell- intro
• Ideal way
CLI

Ps1
Script

GUI

PowerShell
Admin
Engine

APP

Product (any)

Any
future
tech
Windows powershell- intro
Products build on Phase 2 model:
Exchange 2007
Windows 7
System center VM manager (SCVMM)
System center data protection manager(SCDPM)
System center common object manager (SCOM)
Windows powershell- intro
Products built on Phase 1 model:
System center configuration manager (SCCM)
SQL server 2008
VMware EXS
Citrix
F5 Networks
Windows powershell- intro
Tap in existing admin products such as:
WMI
ADSI (Active directory services interface)
.NET Framework
COM (common object model)
Securing the shell
•
•
•
•
•
•

Scripts : the big concern
Execution policy
script signing
profile (and back doors )
Path required (to prevent Command hijacking )
File extension , double click etc
Securing the shell
Scripting disadvantages :
•
•
•
•

No integrity
No identity
Command hijacking (path required to run ps1)
Double click to run
Securing the shell
Execution policy :





restricted
all signed
remote signed
unrestricted
Securing the shell
script signing :

Script
PS1

ID

Encr
Script
Securing the shell
script signing :
CA

Certificate

(PKI)

Class III
 Is the script signed

Script

Sign
Get-ExecutionPolicy
Set-ExecutionPolicy
Set-AuthenticodeSignature

 Is the script signature intact
 Do u trust this CA
Using shell for file and folder management
•
•
•
•

Common commands
Slight difference (-recursive, -filter )
Spaces & quotes
PSDrive
-adding and using
- differences
• Redirecting out put (| Out-file )
• Displaying text files
Using shell for file and folder management
PSDrive:
Get-psdrive
New-psdrive
www.codeplex/powershellcx
Command-lets, Snap-Ins, Aliases, and Help

•
•
•
•
•
•

Quotes ‘ and “
Escaping
Tab completion & cmd history
-path vs –literalpath
Transcripts (Start-Transcript)
Different consoles

Diff consoles
CLI
PrmilSciript
Power
shell

PowerGUI
PowerShell+
Command-Line Tips, Tricks, and Gotchas
Get-command (gcm):
Get-command
Get-command -verb –noun
Get-command -noun services
Get-command -verb new
Command-Line Tips, Tricks, and Gotchas
Cmdlets:
Verb

Get
Set
New

-

Singular noun

Eventlog
ChildItem
ExecutionPolicy
AuthenticodeSignature
Location
process

space

name

Security
'Program
Files‘
svchost

space

-Paramter /
-parameters

-Recurse
-Filter
-Path
-LiteralPath
-Newest

space

values
Command-lets, Snap-Ins, Aliases, and Help
Get-command (gcm):
Get-command
Get-command -verb –noun
Get-command -noun services
Get-command -verb new
Command-lets, Snap-Ins, Aliases, and Help

•
•
•
•
•
•
•
•

Aliases & cmdlets
Get-command
Ask for help
Reading the help
Parameter prompting
All about aliases (New-Alias, Export-Alias, import- -Alias)
Pssnapins (Get-PSSnapin –Registered, add-PSSnapin, Export-Console psc1 ,
-PSConsoleFile)
Custom console s (& profiles)
Basic Command-lets for Processes, Services, and
Event Logs

• Process (Get-Process,ps , Stop-Process kill)
• Services
• Eventlogs(Common Parameters, -whatif, Get-EventLog security Newest 5 | Format-List *, fl)
• Display tips
• What’s missing
• Local vs remote
Basic Command-lets for Processes, Services, and
Event Logs
Services:

Get-Service(gsv)
Stop-Service
Start-Service
Suspend-Service
Resume-Service
Restart-Service
Set-Service
New-Service (Get-Credentila)
Basic Command-lets for Processes, Services, and
Event Logs
Cmdlets
Built on .Net framework
Non-remoting
Easy
Built-in help

WMI
it’s own architure
remoting
complicated
no built-in help
Retrieving Management Information from
Remote Computers

•
•
•
•
•

Interdiction to WMI
Exploring WMI
Remote WMI
Alternative credentials
Filtering WMI data
Retrieving Management Information from
Remote Computers
What is WMI
DMTF(Desktop (or distributed) Management Task Force)
CIM (Common Information Model ) (CIM v2)
WBEM(Web Base Enterprise Model) (with IIS v5)

WMI
Retrieving Management Information from
Remote Computers
What is WMI

WMI

CIM
provider

provider

provider

provider

windows

Exchange

IIS

SQL
Retrieving Management Information from
Remote Computers
What is WMI

Namespaces (IIS,DNS) (each namespace have a class)
root/CIMv2 for core OS

Classes (CIM) (each class is an manageable object )
-disk
-CPU
-A rec DNS
-web IIS

Instance (each instance is a subset of a class object )
each object will have separate instance
eg: hdd
CPU
Retrieving Management Information from
Remote Computers
What is WMI
WMIExplorer : (Methods , instance, properties )
Eg:
Win32_operatingsystem
Win32_diskpartiation
win32_service
Retrieving Management Information from
Remote Computers
Back to powershell
Get-WmiObject(gwmi)
win32_service
Get-WmiObject win32_service -Filter "name like 'sh%'“
gwmi win32_service -Filter "name =‘SharedAccess'“
gwmi win32_operatingsystem
gwmi win32_operatingsystem | fl *
gwmi win32_operatingsystem -computername (or -comp) “itdse”,”swpark”
gwmi win32_operatingsystem -comp (type c:abc.txt)
gwmi win32_operatingsystem -comp localhost –cre(Get-Credential)
Retrieving Management Information from
Remote Computers(mmc)
Retrieving Management Information from
Remote Computers
Powershell relational operators for WMI:
For all numeric and date :
=
>
>=
<
<=
Eg: =80
For strings (with an ‘ ’)
Like
Eg: like name =‘svc%’
Retrieving Management Information from
Remote Computers

•
•
•
•
•

Interdiction to WMI
Exploring WMI
Remote WMI
Alternative credentials
Filtering WMI data
Using Variables, Objects, and Members

•
•
•
•
•
•
•
•

What are variables
Creating, populating, displaying
Interdiction to objects
Simple objects
Viewing object members
Objects in variables
Removing variables
Example credential storage
Using Variables, Objects, and Members
New-Variable -name a -value 10
$b = 3
PS C:> $b
3
PS C:> $a
10
PS C:> $sum = $a + $b
PS C:> $sum
13
$object = “hello”
$object.length
$object.toupper()
[string]$var =“hello”
$dt=get-date
[string], [int], [datetime]
Get-Member(gm)
$dt|gm
$var|gm
ps | gm
Get-service | gm
Gwmi | gm
$proc = get-process
$proc*0+,*1+…. *-1]
$proc[0] | gm
$proc[0].kill()
Using Variables, Objects, and Members
Remove-Variable –name a
Del
$cred = Get-Credential
Understanding the Pipeline

•
•
•
•
•
•
•

Why pipeline ? (it is the power in powershell)
Visualizing pipeline
Services in pipeline
Process in pipeline
Piping to file or printer
Write-output
Write-host
Understanding the Pipeline
The unix / linux way
Clear txt or some character file
CMD

GREP

PID Name Responding
01 xxy
02 xxz
03 xxx

config

true
true
false
KILL
Understanding the Pipeline
Bill gates never shamed to copy
Get-services

|

Where-object

|
Objects after filtering

|

Formit-list

|

objects

Get-services

|

|

out-default

Formatted Object as o/p
Understanding the Pipeline
Piping is the power in powershell
Get-Service | Where-Object {$_.status -eq "running"}
Get-Service | Where-Object {$_.status -eq "running“-| fl *
Get-Service | Where-Object {$_.status -eq "running"} | out-default
Get-Service | Where-Object {$_.status -eq "stopped" } | Set-Service -StartupType disabled –whatif
Get-Service | Where-Object {$_.status -eq "stopped" } | start-serivace –whatif
Get-process | stop-process –whatif
Understanding the Pipeline
BDL scenario

Get-wmiobjet

|

Where –object
{filetype = mp3}

|

del

Get-wmiobjet

|

Where –object
{versiontype = xx.o}

|

update

Get-wmiobjet

|

Where –object {file
= xxx}

|

copy

Eg: Get-WmiObject Win32_Directory | where-object {filetype = mp3} | del
Understanding the Pipeline
Write-Out (-verb out)
Get-Service | Out-File c:sun.txt
Get-Service | Out-Printer hp1005
Write-output “Hello” (Writes objects to the success pipeline)
Write-host “Hello” (Displays objects by using the host user interface)
Write-Output "Hello" | Where-Object {$_.Length -gt 100 } (will display nothing)
Write-Host "Hello" | Where-Object {$_.Length -gt 100 } (will display Hello)
Mathematical and Comparison Operators
•
•
•
•
•
•
•

Basic +, -, *, /,%
Comparison operators –eq, -gt, -lt, -ge , -le(for both numiric, and string and concatenate –c
before cmp operator to obtain case sensitive cmp)
Bolin operators –and, -or , -not,
Advance math
Basic comparisons
Case sensitivity
Parsing model
-command
-expression

Eg: Get-WmiObject win32_service -computername localhost,sunil | where {$_.StartAuto -eq "Auto" -and
$_.State -ne "Running"}
Sorting, Measuring, Selecting and Filtering
Objects in the Pipeline

•
•
•
•
•
•

Sorting
Measuring
Selecting properties
Selecting subset
Filtering
Powershell work flow
Sorting, Measuring, Selecting and Filtering
Objects in the Pipeline
Sorting :
Eg: get-process | Sort-Object CPU
ps | Sort CPU –Descending

Measuring
eg: get-process | Measure-Object
gsv | Measure-Object
get-process | Measure-Object -Property pm -sum -min -max –average
get-service | Measure-Object -Property displayname -line -word -Character
Sorting, Measuring, Selecting and Filtering
Objects in the Pipeline
Select object and where object:
Eg: get-service | Select-Object displayname, dependentservices
get-process | select-object ProcessName,Id,VM
Get-Process | Where { $_.Name -Eq "calc" } | Kill
Get-service | Where { $_.status -eq "stopped" } | Start-Service –WhatIf
Get-service | Where { $_.name -eq "browser" } | Start-Service
Get-WmiObject win32_service -comp "sunil" | where {$_.name -match
"browser"}
Get-WmiObject win32_service -comp “itdse“,”swpark” | where ,$_.name -like
"browser"}
Working with Collections of Objects in the
Pipeline

•
•
•
•

Object collections
Working with groups
Working with individuals
Foreach-object (%) & wmi
Working with Collections of Objects in the
Pipeline
Object collections & foreach-object(%)
Eg: type c:abc.txt| ForEach-Object {gwmi win32_operatingsystem -computername
$_}
type c:abc.txt| % {gwmi win32_operatingsystem -computername $_ | % {
$_.reboot() } }
Understanding and Using the Formatting
Subsystem
• How objects become text
• Text in the console window
• Formatting the sub system
-format-wide
-format-list
-format-table
• Custom columns in table
• Hash table
Understanding and Using the Formatting
Subsystem

PS

Out-default

Format
subsystem

Out-host
Understanding and Using the Formatting
Subsystem
Get-Service | Format-Wide
Get-Service | fw displayname
Get-Service | Fw displayname -col 3
Get-Service | Format-List displayname,name,status
Get-Service | sort status | Fl displayname,name,status -GroupBy status
Get-Service | sort status| Format-Table displayname,status,DependentServices –auto
Get-Service | sort status| Format-Table displayname,status,DependentServices -auto -GroupBy status
gwmi win32_logicaldisk FileSystem
gwmi win32_logicaldisk | ft deviceid,volumename,size
gwmi win32_logicaldisk | ft deviceid,volumename,size,freespace –auto
PS C:> gwmi win32_logicaldisk | ft deviceid,volumename,@{ Label="Size" ; Expression = {$_.size / 1gb } },@{ Label="Free
"; Expression = {$_.freespace / 1gb } } -auto
PS C:> gwmi win32_logicaldisk | ft deviceid,volumename,@{ Label ="Size(G)"; Expression={($_.size / 1gb) -as [int]}},@{
Label ="Free(G)";Expression={($_.freespace/1gb) -as [int] } }-auto
Exporting, Importing, Comparing, and
Converting Objects

•
•
•
•
•

Exporting to csv
Importing from csv
CLIxml import/export
Comparing collections
Converting to html
Exporting, Importing, Comparing, and
Converting Objects
Exporting /import csv,html
ps | Export-Csv c:pro.csv
$impps = import-Csv c:pro.csv
$impps[0] | ft –auto
Get-Service | select -first 2 | Export-Clixml c:serx.xml
import-Clixml c:serx.xml
Compare-Object (ps) (import-clixml c:serx.xml)
Diff (ps) (import-clixml c:serx.xml) –property name
gwmi win32_service -computername localhost,sunil | where {$_.StartAuto -eq
"Auto" -and $_.State -ne “Running"-| select startmode, state, name | ConvertToHtml | Out-File c:rep.html

More Related Content

What's hot

Introduction To Windows Power Shell
Introduction To Windows Power ShellIntroduction To Windows Power Shell
Introduction To Windows Power ShellMicrosoft TechNet
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidMatthew Johnson
 
Mastering power shell - Windows
Mastering power shell - WindowsMastering power shell - Windows
Mastering power shell - WindowsAriel Devulsky
 
Introduction to Powershell Version 5
Introduction to Powershell Version 5Introduction to Powershell Version 5
Introduction to Powershell Version 5Nishtha Kesarwani
 
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...Hitesh Mohapatra
 
PM : code faster
PM : code fasterPM : code faster
PM : code fasterPHPPRO
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019Karthik Sekhar
 
Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013Puppet
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJoel Brewer
 
PHP: The Beginning and the Zend
PHP: The Beginning and the ZendPHP: The Beginning and the Zend
PHP: The Beginning and the Zenddoublecompile
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Andreas Jung
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Combell NV
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projectsAndreas Jung
 

What's hot (20)

Introduction To Windows Power Shell
Introduction To Windows Power ShellIntroduction To Windows Power Shell
Introduction To Windows Power Shell
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 
Mastering power shell - Windows
Mastering power shell - WindowsMastering power shell - Windows
Mastering power shell - Windows
 
PowerShell-1
PowerShell-1PowerShell-1
PowerShell-1
 
Introduction to Powershell Version 5
Introduction to Powershell Version 5Introduction to Powershell Version 5
Introduction to Powershell Version 5
 
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Network programming
Network programmingNetwork programming
Network programming
 
PHP: The Beginning and the Zend
PHP: The Beginning and the ZendPHP: The Beginning and the Zend
PHP: The Beginning and the Zend
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
 
Migration from ASP to ASP.NET
Migration from ASP to ASP.NETMigration from ASP to ASP.NET
Migration from ASP to ASP.NET
 
System Programming and Administration
System Programming and AdministrationSystem Programming and Administration
System Programming and Administration
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
 
Firebird
FirebirdFirebird
Firebird
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projects
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 

Similar to Sunil phani's take on windows powershell

Windows Remote Management - EN
Windows Remote Management - ENWindows Remote Management - EN
Windows Remote Management - ENKirill Nikolaev
 
Linux Desktop Automation
Linux Desktop AutomationLinux Desktop Automation
Linux Desktop AutomationRui Lapa
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, PowershellRoo7break
 
VMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep DiveVMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep DiveVMworld
 
Airflow presentation
Airflow presentationAirflow presentation
Airflow presentationIlias Okacha
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Jérôme Petazzoni
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleRoman Rodomansky
 
Containers: The What, Why, and How
Containers: The What, Why, and HowContainers: The What, Why, and How
Containers: The What, Why, and HowSneha Inguva
 
Privilege Escalation with Metasploit
Privilege Escalation with MetasploitPrivilege Escalation with Metasploit
Privilege Escalation with Metasploitegypt
 
Cli jbug
Cli jbugCli jbug
Cli jbugmaeste
 
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment OptionsNagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment OptionsNagios
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetesTed Jung
 
airflowpresentation1-180717183432.pptx
airflowpresentation1-180717183432.pptxairflowpresentation1-180717183432.pptx
airflowpresentation1-180717183432.pptxVIJAYAPRABAP
 
LOAD BALANCING OF APPLICATIONS USING XEN HYPERVISOR
LOAD BALANCING OF APPLICATIONS  USING XEN HYPERVISORLOAD BALANCING OF APPLICATIONS  USING XEN HYPERVISOR
LOAD BALANCING OF APPLICATIONS USING XEN HYPERVISORVanika Kapoor
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operationsgrim_radical
 
24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAsKellyn Pot'Vin-Gorman
 
DevSecCon Singapore 2018 - System call auditing made effective with machine l...
DevSecCon Singapore 2018 - System call auditing made effective with machine l...DevSecCon Singapore 2018 - System call auditing made effective with machine l...
DevSecCon Singapore 2018 - System call auditing made effective with machine l...DevSecCon
 

Similar to Sunil phani's take on windows powershell (20)

Windows Remote Management - EN
Windows Remote Management - ENWindows Remote Management - EN
Windows Remote Management - EN
 
Linux Desktop Automation
Linux Desktop AutomationLinux Desktop Automation
Linux Desktop Automation
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
 
VMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep DiveVMworld 2013: PowerCLI Best Practices - A Deep Dive
VMworld 2013: PowerCLI Best Practices - A Deep Dive
 
Airflow presentation
Airflow presentationAirflow presentation
Airflow presentation
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with Ansible
 
Containers: The What, Why, and How
Containers: The What, Why, and HowContainers: The What, Why, and How
Containers: The What, Why, and How
 
PowerShell Remoting
PowerShell RemotingPowerShell Remoting
PowerShell Remoting
 
Privilege Escalation with Metasploit
Privilege Escalation with MetasploitPrivilege Escalation with Metasploit
Privilege Escalation with Metasploit
 
Cli jbug
Cli jbugCli jbug
Cli jbug
 
AS7 and CLI
AS7 and CLIAS7 and CLI
AS7 and CLI
 
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment OptionsNagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
Nagios Conference 2014 - Mike Weber - Nagios Rapid Deployment Options
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
 
airflowpresentation1-180717183432.pptx
airflowpresentation1-180717183432.pptxairflowpresentation1-180717183432.pptx
airflowpresentation1-180717183432.pptx
 
LOAD BALANCING OF APPLICATIONS USING XEN HYPERVISOR
LOAD BALANCING OF APPLICATIONS  USING XEN HYPERVISORLOAD BALANCING OF APPLICATIONS  USING XEN HYPERVISOR
LOAD BALANCING OF APPLICATIONS USING XEN HYPERVISOR
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
Powershell
PowershellPowershell
Powershell
 
24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs
 
DevSecCon Singapore 2018 - System call auditing made effective with machine l...
DevSecCon Singapore 2018 - System call auditing made effective with machine l...DevSecCon Singapore 2018 - System call auditing made effective with machine l...
DevSecCon Singapore 2018 - System call auditing made effective with machine l...
 

Recently uploaded

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Sunil phani's take on windows powershell

  • 1. A Sunil Phani’s take on Windows powershell
  • 2. Windows powershell- course - Why should we care? What powershell is? Securing the shell File and folder management Command line tips , tricks & gotchs
  • 3. Windows powershell- course - Cmdlets, snapins, aliases ,help - Basic cmdlets : processes , services, & event logs - Retriving mgmt info from Remote computers (WMI)
  • 4. Windows powershell- course - using variables ,objects , & Members Understanding pipeline Math & comparison operators Sorting, measuring, selecting & filtering Working with collection of objects
  • 5. Windows powershell- course - Formatting subsystem - Exporting, converting, importing & comparing - Managing active directory(and local), users, groups etc,. - Windows powershell scripts
  • 6. Windows powershell- course - The scripting language (with just 14 key words) Script blocks & functions Custom blocks in functions Err or trapping & handling Script debugging Regular expressions
  • 7. Windows powershell- intro • • • • The old way vs new way An administrative engine Existing and up coming products Customizing shell
  • 8. Windows powershell- intro • Interim (phase 1) C.E.C Snap in T-SQL GUI (MMC) Service Product ( eg. SQL 2005) exe data PSH Config
  • 9. Windows powershell- intro • New way (Phase 2) CLI Scripts GUI Powershell Product ( eg. Ex change 2007 )
  • 10. Windows powershell- intro • Old way C.E.C Snap in GUI (MMC) Service Product ( eg. Ex change ) exe Bat WMI data COM VBS Config
  • 11. Windows powershell- intro • Ideal way CLI Ps1 Script GUI PowerShell Admin Engine APP Product (any) Any future tech
  • 12. Windows powershell- intro Products build on Phase 2 model: Exchange 2007 Windows 7 System center VM manager (SCVMM) System center data protection manager(SCDPM) System center common object manager (SCOM)
  • 13. Windows powershell- intro Products built on Phase 1 model: System center configuration manager (SCCM) SQL server 2008 VMware EXS Citrix F5 Networks
  • 14. Windows powershell- intro Tap in existing admin products such as: WMI ADSI (Active directory services interface) .NET Framework COM (common object model)
  • 15. Securing the shell • • • • • • Scripts : the big concern Execution policy script signing profile (and back doors ) Path required (to prevent Command hijacking ) File extension , double click etc
  • 16. Securing the shell Scripting disadvantages : • • • • No integrity No identity Command hijacking (path required to run ps1) Double click to run
  • 17. Securing the shell Execution policy :     restricted all signed remote signed unrestricted
  • 18. Securing the shell script signing : Script PS1 ID Encr Script
  • 19. Securing the shell script signing : CA Certificate (PKI) Class III  Is the script signed Script Sign Get-ExecutionPolicy Set-ExecutionPolicy Set-AuthenticodeSignature  Is the script signature intact  Do u trust this CA
  • 20. Using shell for file and folder management • • • • Common commands Slight difference (-recursive, -filter ) Spaces & quotes PSDrive -adding and using - differences • Redirecting out put (| Out-file ) • Displaying text files
  • 21. Using shell for file and folder management PSDrive: Get-psdrive New-psdrive www.codeplex/powershellcx
  • 22. Command-lets, Snap-Ins, Aliases, and Help • • • • • • Quotes ‘ and “ Escaping Tab completion & cmd history -path vs –literalpath Transcripts (Start-Transcript) Different consoles Diff consoles CLI PrmilSciript Power shell PowerGUI PowerShell+
  • 23. Command-Line Tips, Tricks, and Gotchas Get-command (gcm): Get-command Get-command -verb –noun Get-command -noun services Get-command -verb new
  • 24. Command-Line Tips, Tricks, and Gotchas Cmdlets: Verb Get Set New - Singular noun Eventlog ChildItem ExecutionPolicy AuthenticodeSignature Location process space name Security 'Program Files‘ svchost space -Paramter / -parameters -Recurse -Filter -Path -LiteralPath -Newest space values
  • 25. Command-lets, Snap-Ins, Aliases, and Help Get-command (gcm): Get-command Get-command -verb –noun Get-command -noun services Get-command -verb new
  • 26. Command-lets, Snap-Ins, Aliases, and Help • • • • • • • • Aliases & cmdlets Get-command Ask for help Reading the help Parameter prompting All about aliases (New-Alias, Export-Alias, import- -Alias) Pssnapins (Get-PSSnapin –Registered, add-PSSnapin, Export-Console psc1 , -PSConsoleFile) Custom console s (& profiles)
  • 27. Basic Command-lets for Processes, Services, and Event Logs • Process (Get-Process,ps , Stop-Process kill) • Services • Eventlogs(Common Parameters, -whatif, Get-EventLog security Newest 5 | Format-List *, fl) • Display tips • What’s missing • Local vs remote
  • 28. Basic Command-lets for Processes, Services, and Event Logs Services: Get-Service(gsv) Stop-Service Start-Service Suspend-Service Resume-Service Restart-Service Set-Service New-Service (Get-Credentila)
  • 29. Basic Command-lets for Processes, Services, and Event Logs Cmdlets Built on .Net framework Non-remoting Easy Built-in help WMI it’s own architure remoting complicated no built-in help
  • 30. Retrieving Management Information from Remote Computers • • • • • Interdiction to WMI Exploring WMI Remote WMI Alternative credentials Filtering WMI data
  • 31. Retrieving Management Information from Remote Computers What is WMI DMTF(Desktop (or distributed) Management Task Force) CIM (Common Information Model ) (CIM v2) WBEM(Web Base Enterprise Model) (with IIS v5) WMI
  • 32. Retrieving Management Information from Remote Computers What is WMI WMI CIM provider provider provider provider windows Exchange IIS SQL
  • 33. Retrieving Management Information from Remote Computers What is WMI Namespaces (IIS,DNS) (each namespace have a class) root/CIMv2 for core OS Classes (CIM) (each class is an manageable object ) -disk -CPU -A rec DNS -web IIS Instance (each instance is a subset of a class object ) each object will have separate instance eg: hdd CPU
  • 34. Retrieving Management Information from Remote Computers What is WMI WMIExplorer : (Methods , instance, properties ) Eg: Win32_operatingsystem Win32_diskpartiation win32_service
  • 35. Retrieving Management Information from Remote Computers Back to powershell Get-WmiObject(gwmi) win32_service Get-WmiObject win32_service -Filter "name like 'sh%'“ gwmi win32_service -Filter "name =‘SharedAccess'“ gwmi win32_operatingsystem gwmi win32_operatingsystem | fl * gwmi win32_operatingsystem -computername (or -comp) “itdse”,”swpark” gwmi win32_operatingsystem -comp (type c:abc.txt) gwmi win32_operatingsystem -comp localhost –cre(Get-Credential)
  • 36. Retrieving Management Information from Remote Computers(mmc)
  • 37. Retrieving Management Information from Remote Computers Powershell relational operators for WMI: For all numeric and date : = > >= < <= Eg: =80 For strings (with an ‘ ’) Like Eg: like name =‘svc%’
  • 38. Retrieving Management Information from Remote Computers • • • • • Interdiction to WMI Exploring WMI Remote WMI Alternative credentials Filtering WMI data
  • 39. Using Variables, Objects, and Members • • • • • • • • What are variables Creating, populating, displaying Interdiction to objects Simple objects Viewing object members Objects in variables Removing variables Example credential storage
  • 40. Using Variables, Objects, and Members New-Variable -name a -value 10 $b = 3 PS C:> $b 3 PS C:> $a 10 PS C:> $sum = $a + $b PS C:> $sum 13 $object = “hello” $object.length $object.toupper() [string]$var =“hello” $dt=get-date [string], [int], [datetime] Get-Member(gm) $dt|gm $var|gm ps | gm Get-service | gm Gwmi | gm $proc = get-process $proc*0+,*1+…. *-1] $proc[0] | gm $proc[0].kill()
  • 41. Using Variables, Objects, and Members Remove-Variable –name a Del $cred = Get-Credential
  • 42. Understanding the Pipeline • • • • • • • Why pipeline ? (it is the power in powershell) Visualizing pipeline Services in pipeline Process in pipeline Piping to file or printer Write-output Write-host
  • 43. Understanding the Pipeline The unix / linux way Clear txt or some character file CMD GREP PID Name Responding 01 xxy 02 xxz 03 xxx config true true false KILL
  • 44. Understanding the Pipeline Bill gates never shamed to copy Get-services | Where-object | Objects after filtering | Formit-list | objects Get-services | | out-default Formatted Object as o/p
  • 45. Understanding the Pipeline Piping is the power in powershell Get-Service | Where-Object {$_.status -eq "running"} Get-Service | Where-Object {$_.status -eq "running“-| fl * Get-Service | Where-Object {$_.status -eq "running"} | out-default Get-Service | Where-Object {$_.status -eq "stopped" } | Set-Service -StartupType disabled –whatif Get-Service | Where-Object {$_.status -eq "stopped" } | start-serivace –whatif Get-process | stop-process –whatif
  • 46. Understanding the Pipeline BDL scenario Get-wmiobjet | Where –object {filetype = mp3} | del Get-wmiobjet | Where –object {versiontype = xx.o} | update Get-wmiobjet | Where –object {file = xxx} | copy Eg: Get-WmiObject Win32_Directory | where-object {filetype = mp3} | del
  • 47. Understanding the Pipeline Write-Out (-verb out) Get-Service | Out-File c:sun.txt Get-Service | Out-Printer hp1005 Write-output “Hello” (Writes objects to the success pipeline) Write-host “Hello” (Displays objects by using the host user interface) Write-Output "Hello" | Where-Object {$_.Length -gt 100 } (will display nothing) Write-Host "Hello" | Where-Object {$_.Length -gt 100 } (will display Hello)
  • 48. Mathematical and Comparison Operators • • • • • • • Basic +, -, *, /,% Comparison operators –eq, -gt, -lt, -ge , -le(for both numiric, and string and concatenate –c before cmp operator to obtain case sensitive cmp) Bolin operators –and, -or , -not, Advance math Basic comparisons Case sensitivity Parsing model -command -expression Eg: Get-WmiObject win32_service -computername localhost,sunil | where {$_.StartAuto -eq "Auto" -and $_.State -ne "Running"}
  • 49. Sorting, Measuring, Selecting and Filtering Objects in the Pipeline • • • • • • Sorting Measuring Selecting properties Selecting subset Filtering Powershell work flow
  • 50. Sorting, Measuring, Selecting and Filtering Objects in the Pipeline Sorting : Eg: get-process | Sort-Object CPU ps | Sort CPU –Descending Measuring eg: get-process | Measure-Object gsv | Measure-Object get-process | Measure-Object -Property pm -sum -min -max –average get-service | Measure-Object -Property displayname -line -word -Character
  • 51. Sorting, Measuring, Selecting and Filtering Objects in the Pipeline Select object and where object: Eg: get-service | Select-Object displayname, dependentservices get-process | select-object ProcessName,Id,VM Get-Process | Where { $_.Name -Eq "calc" } | Kill Get-service | Where { $_.status -eq "stopped" } | Start-Service –WhatIf Get-service | Where { $_.name -eq "browser" } | Start-Service Get-WmiObject win32_service -comp "sunil" | where {$_.name -match "browser"} Get-WmiObject win32_service -comp “itdse“,”swpark” | where ,$_.name -like "browser"}
  • 52. Working with Collections of Objects in the Pipeline • • • • Object collections Working with groups Working with individuals Foreach-object (%) & wmi
  • 53. Working with Collections of Objects in the Pipeline Object collections & foreach-object(%) Eg: type c:abc.txt| ForEach-Object {gwmi win32_operatingsystem -computername $_} type c:abc.txt| % {gwmi win32_operatingsystem -computername $_ | % { $_.reboot() } }
  • 54. Understanding and Using the Formatting Subsystem • How objects become text • Text in the console window • Formatting the sub system -format-wide -format-list -format-table • Custom columns in table • Hash table
  • 55. Understanding and Using the Formatting Subsystem PS Out-default Format subsystem Out-host
  • 56. Understanding and Using the Formatting Subsystem Get-Service | Format-Wide Get-Service | fw displayname Get-Service | Fw displayname -col 3 Get-Service | Format-List displayname,name,status Get-Service | sort status | Fl displayname,name,status -GroupBy status Get-Service | sort status| Format-Table displayname,status,DependentServices –auto Get-Service | sort status| Format-Table displayname,status,DependentServices -auto -GroupBy status gwmi win32_logicaldisk FileSystem gwmi win32_logicaldisk | ft deviceid,volumename,size gwmi win32_logicaldisk | ft deviceid,volumename,size,freespace –auto PS C:> gwmi win32_logicaldisk | ft deviceid,volumename,@{ Label="Size" ; Expression = {$_.size / 1gb } },@{ Label="Free "; Expression = {$_.freespace / 1gb } } -auto PS C:> gwmi win32_logicaldisk | ft deviceid,volumename,@{ Label ="Size(G)"; Expression={($_.size / 1gb) -as [int]}},@{ Label ="Free(G)";Expression={($_.freespace/1gb) -as [int] } }-auto
  • 57. Exporting, Importing, Comparing, and Converting Objects • • • • • Exporting to csv Importing from csv CLIxml import/export Comparing collections Converting to html
  • 58. Exporting, Importing, Comparing, and Converting Objects Exporting /import csv,html ps | Export-Csv c:pro.csv $impps = import-Csv c:pro.csv $impps[0] | ft –auto Get-Service | select -first 2 | Export-Clixml c:serx.xml import-Clixml c:serx.xml Compare-Object (ps) (import-clixml c:serx.xml) Diff (ps) (import-clixml c:serx.xml) –property name gwmi win32_service -computername localhost,sunil | where {$_.StartAuto -eq "Auto" -and $_.State -ne “Running"-| select startmode, state, name | ConvertToHtml | Out-File c:rep.html