To specify the properties of the input object to
represent within the HTML table, use the -property parameter and to specify the
text to include within the <body> element of the HTML output, use the
-body parameter.
The -head and -title parameters can also be used to
specify the text to be included in the respective tags.
Examples
This command uses the Get-Date cmdlet to create a DateTime
object and pipe it to the ConvertTo-HTML cmdlet. The cmdlet creates an HTML page
that includes an HTML table that represents the object. The HTML output is
displayed at the console
PS D:\Users\bala> get-date | convertto-html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<tr><th>DisplayHint</th> <th>DateTime</th><th>Date</th><th>Day</th> <th>DayOfWeek</th><th>DayOfYear</th><th>Hour</th><th>
Kind</th><th>Millisecond</th><th>Minute</th><th>Month</th> <th>Second</th><th>Ticks</th><th>TimeOfDay</th><th>Year</th><
/tr>
<tr><td>DateTime</td><td>17
February 2008 10:26:11</td><td>17-02-2008
00:00:00</td><td>17</td><td>Sunday</td><td>48</td
><td>10</td><td>Local</td><td>373</td> <td>26</td><td>2</td><td>11</td><td>633388407713730745</td><td>10:26:11.3730745</
td><td>2008</td></tr>
</table></body></html>
This command uses the Get-Process cmdlet to retrieve a set of
objects that contain information about the processes, their name starting with
letter "w" running on the computer. It pipes those objects to the ConvertTo-HTML
cmdlet, which creates an HTML page that includes an HTML table that represents
the objects. The Properties parameter is used to specify the properties of the
objects that are represented in the table. The Title parameter specifies the
title of the HTML page. The redirection operator (>) is used to send the
resulting HTML to a file named proc.htm. Finally, the Invoke-Item cmdlet is used
to open the proc.htm file in the application associated with the .htm file name
extension.
PS D:\Users\bala> get-process w* | convertto-html
-property name, path, company -title "Process Information" > proc.htm
PS D:\Users\bala> type proc.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Process Information</title>
</head><body>
<table>
<colgroup>
<col>
<col>
<col>
</colgroup>
<tr><th>name</th><th>path</th><th>company</th></tr>
<tr><td>wininit</td><td></td><td></td></tr>
<tr><td>winlogon</td><td></td><td></td></tr>
<tr><td>wmpnetwk</td><td></td><td></td></tr>
<tr><td>wmpnscfg</td><td>D:\Program
Files\Windows Media Player\wmpnscfg.exe</td><td>Microsoft
Corporation</td></tr>
<tr><td>wuauclt</td><td>D:\Windows\system32\wuauclt.exe</td><td>Microsoft
Corporation</td></tr>
<tr><td>wweb32</td><td>D:\Program
Files\WordWeb\wweb32.exe</td><td>Antony
Lewis</td></tr>
</table></body></html>
To view the HTML file in the browser, issue the following
command.
PS D:\Users\bala> invoke-item proc.htm
Convert-Path
This cmdlet converts a path from a Windows PowerShell path to
a Windows PowerShell provider path.
The -path specifies the Windows PowerShell path to be
converted.
The -literalPath specifies the path to be converted. The
value of -LiteralPath is used exactly as it is typed. No characters are
interpreted as wildcards. If the path includes escape characters, enclose it in
single quotation marks. Single quotation marks tell Windows PowerShell not
to interpret any characters as escape sequences.
cvpa is the alias for this cmdlet.
Examples
This command expands the current working directory.
PS D:\Users\bala> convert-path ~
D:\Users\bala
This command converts the Windows PowerShell provider path to
a standard registry path.
PS D:\Users\bala> convert-path
hklm:\software\microsoft
HKEY_LOCAL_MACHINE\software\microsoft
Resolve-Path
Resolve-path cmdlet interprets the wildcard characters in a
path and displays the items and containers at the location specified by the
path, such as the files and folders or registry keys and subkeys. The names
appear just as they are represented in the drive, including capitalization..
The -path parameter specifies the Windows PowerShell path to
resolve. The -literalPath parameter specifies the path to be resolved. The value
of -LiteralPath is used exactly as it is typed. No characters are interpreted as
wildcards. If the path includes escape characters, enclose it in single
quotation marks. Single quotation marks tell Windows PowerShell not to interpret
any characters as escape sequences.
Examples
The ~ character signifies the home path. This example will
return the full home path.
PS D:\Users\bala> resolve-path ~ | format-list
Drive : D
Provider : Microsoft.PowerShell.Core\FileSystem
ProviderPath : D:\Users\bala
Path : D:\Users\bala
This example starts at the current location and returns the
paths to all items in the Windows folder.
D:\Users\bala> resolve-path d:\windows\*
Path
----
D:\windows\addins
D:\windows\AppPatch
D:\windows\assembly
D:\windows\ATK0100
D:\windows\Boot
D:\windows\Branding
D:\windows\CSC
D:\windows\Cursors
D:\windows\Debug
D:\windows\DigitalLocker
........
........
Get-WmiObject
This command gets instances of WMI classes or information
about available classes. The ComputerName parameter can always be used to
target a remote computer. If the List parameter is specified, the cmdlet gets
information about the WMI classes available in a specified namespace. If the
Query parameter is specified, the cmdlet runs a WMI query language (WQL)
statement.
The -class and -property parameters specifies the name of a
WMI class and its property or set of properties to retrieve.
The -namespace parameter specifies the WMI repository
namespace where the referenced WMI class is located. The -credential
parameter uses the specified credential to authenticate the user.
Examples
This command displays information about all of the processes
running on a computer.
PS D:\Users\bala> get-wmiobject win32_process -property
Name
__GENUS : 2
__CLASS : Win32_Process
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
Name : System Idle Process
__GENUS : 2
__CLASS : Win32_Process
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
Name : System
__GENUS : 2
__CLASS : Win32_Process
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
Name : smss.exe
This command displays information about the services on the
local computer. It does so by specifying the IP address 127.0.0.1. This IP
address can be changed to any other valid IP address on your network, enabling
you to display information about the services on that remote computer. By
default, the account you are running under must be a member of the local
administrators group on the remote computer you specify for the command to
succeed.
PS D:\Users\bala> get-wmiobject win32_service -computer
127.0.0.1
ExitCode : 0
Name : AeLookupSvc
ProcessId : 984
StartMode : Auto
State : Running
Status : OK
ExitCode : 1077
Name : ALG
ProcessId : 0
StartMode : Manual
State : Stopped
Status : OK
ExitCode : 1077
Name : Appinfo
ProcessId : 0
StartMode : Manual
State : Stopped
Status : OK
This command displays the WMI classes in the root/default
namespace of the local computer.
PS D:\Users\bala> get-wmiobject -namespace
"root/default" -list
__NotifyStatus
__ExtendedStatus
__SecurityRelatedClass
__Trustee
__NTLMUser9X
__ACE
__SecurityDescriptor
__PARAMETERS
__SystemClass
__ProviderRegistration
__EventProviderRegistration
__ObjectProviderRegistration
__ClassProviderRegistration
__InstanceProviderRegistration
__MethodProviderRegistration
__PropertyProviderRegistration
__EventConsumerProviderRegistration
__thisNAMESPACE
__NAMESPACE
__IndicationRelated
__FilterToConsumerBinding
__EventConsumer
LogFileEventConsumer
ActiveScriptEventConsumer
NTEventLogEventConsumer
SMTPEventConsumer
CommandLineEventConsumer
__AggregateEvent
__TimerNextFiring
__EventFilter
__Event
__NamespaceOperationEvent
__NamespaceModificationEvent
__NamespaceDeletionEvent
__NamespaceCreationEvent
__ClassOperationEvent
__ClassDeletionEvent
__ClassModificationEvent
__ClassCreationEvent
__InstanceOperationEvent
__InstanceCreationEvent
__MethodInvocationEvent
__InstanceModificationEvent
__InstanceDeletionEvent
__TimerEvent
__ExtrinsicEvent
__SystemEvent
__EventDroppedEvent
__EventQueueOverflowEvent
__QOSFailureEvent
__ConsumerFailureEvent
RegistryEvent
RegistryKeyChangeEvent
RegistryTreeChangeEvent
RegistryValueChangeEvent
__EventGenerator
__TimerInstruction
__AbsoluteTimerInstruction
__IntervalTimerInstruction
__Provider
__Win32Provider
__CIMOMIdentification
__AdapStatus
__SystemSecurity
StdRegProv
SystemRestoreConfig
SystemRestore
This command displays information about the IIS admin
service.
PS D:\Users\bala> get-wmiobject -query "select * from
win32_service where name='iisadmin'"
ExitCode : 0
Name : IISADMIN
ProcessId : 1904
StartMode : Auto
State : Running
Status : OK
You may run the above command to display IISadmin service
information on a computer named balamurali-b. It specifies a user account name
by using the Credential parameter, which causes a dialog to be displayed to
gather the corresponding password.
PS D:\Users\bala> get-wmiobject -query "select name from
win32_service where name='iisadmin'" -credential balamurali-b\bala -computer
balamurali-b
Get-History
The Get-History cmdlet gets the session history, that is, the
list of commands entered during the current session. Windows PowerShell
automatically maintains a history of each session. You can save the session
history in XML or CSV format. By default, history files are saved in the home
directory, but you can save the file in any location.
The -id parameter specifies the ID number of a command in
the session history. Get-History gets only the specified command.
The -count parameter displays the specified number of
most-recent history entries. The default is 32. If you use both Count and Id in
a command, the display ends with the command specified by Id.
Examples
This command gets the 32 most recently submitted commands.
The default display shows each command and its ID, which indicates the order of
execution.
PS D:\Users\bala> get-history
Id CommandLine
-- -----------
1 cls
2 dir
3 get-wmiobject
4 get-wmiobject win32_process
5 get-wmiobject win32_service
This command gets entries from the command history that
include the word, "service". The first command gets the 32 most recent entries
in the session history. The pipeline operator (|) passes the results to the
Where-Object cmdlet , which selects only the commands that include
"service".
PS D:\Users\bala> get-history | where-object
{$_.commandLine -like "*service*"}
Id CommandLine
-- -----------
12 get-wmiobject win32_service
This command gets the 5 most recent history entries ending
with entry 7. The pipeline operator (|) passes the result to the Export-Csv
cmdlet, which formats the history as comma-separated text and saves it in the
History.csv file. The file includes the data that is displayed when you format
the history as a list, including the status and start and end times of the
command.
PS D:\Users\bala> get-history -id 7 -count 5 |
export-csv history.csv
This command gets the last (most recently entered) command in
the command history. It uses the Count parameter to display just one command. By
default, Get-History displays the most recent commands. This command can be
abbreviated to "h -c 1" and is equivalent to pressing the up-arrow key.
PS D:\Users\bala> get-history -count 1
Id CommandLine
-- -----------
20 get-history -id 2
This command displays all of the commands saved in the
session history. By default, $MaximumHistoryCount is 64, so this command can be
abbreviated as "h -c 64".
PS D:\Users\bala> get-history -count
$maximumhistorycount
Id CommandLine
-- -----------
1 get-wmiobject win32_process
2 get-wmiobject win32_service
3 cls
4 get-history
5 get-history | where-object {$_.commandLine -like
"*service*"}
6 get-history -id 7 -count 5 | export-csv history.csv
7 get-history -id -1
8 get-history -id 1
9 get-history -id 1
10 get-history -id 2
11 get-history -count 1
You may use format-list cmdlet along with the get-history
command to display all of the properties of each history entry, including the
ID, status, and start and end times of the command.
Add-History
The Add-History cmdlet adds entries to the end of the session
history, that is, the list of commands entered during the current session. You
can use Get-History to get the commands and pass them to Add-History, or export
the commands to a CSV or XML file, then import the commands, and pass the
imported file to Add-History. You can use this cmdlet to add specific commands
to the history or to create a single history file that includes commands from
more than one session.
The -inputObject adds the specified HistoryInfo objects to
the session history. You can use this parameter to submit a HistoryInfo object
from Get-History, Import-Clixml, or Import-Csv to Add-History.
The -passthru parameter passes the object created by this
cmdlet through the pipeline. By default, this cmdlet does not pass any objects
through the pipeline.
Examples
These commands add the commands typed in one Windows
PowerShell session to the history of a different Windows PowerShell session. The
first command gets objects representing the commands in the history and exports
them to the mycmdlets.csv file. The second command is typed at the command line
of a different session. It uses the Import-Csv cmdlet to import the objects in
the mycmdlets.csv file. The pipeline operator passes the objects to the
Add-History cmdlet, which adds the objects representing the commands in the
mycmdlets.csv file to the current session history.
PS D:\Users\bala> get-history | export-csv
mycmdlets.csv
PS D:\Users\bala> type mycmdlets.csv
#TYPE Microsoft.PowerShell.Commands.HistoryInfo
Id,CommandLine,ExecutionStatus,StartExecutionTime,EndExecutionTime
1,"get-wmiobject win32_process",Completed,"26-02-2008
19:00:02","26-02-2008 19:00:32"
2,"get-wmiobject win32_service",Completed,"26-02-2008
19:00:38","26-02-2008 19:00:54"
3,cls,Completed,"26-02-2008 19:00:55","26-02-2008
19:00:55"
4,get-history,Completed,"26-02-2008 19:01:02","26-02-2008
19:01:02"
5,"get-history | where-object {$_.commandLine -like
""*service*""}",Completed,"26-02-2008 19:02:10","26-02-2008 19:02:10"
6,"get-history -id 7 -count 5 | export-csv
history.csv",Completed,"26-02-2008 19:03:39","26-02-2008 19:03:40"
7,"get-history -id -1",Completed,"26-02-2008
19:07:13","26-02-2008 19:07:14"
PS D:\Users\bala> import-csv mycmdlets.csv |
add-history
The following cmdlets are same as the above example and
produces the same output. Without the Passthru parameter, Add-History does not
generate any output to display.
PS D:\Users\bala> $a = import-csv mycmdlets.csv
PS D:\Users\bala> add-history -inputobject $a
-passthru
or
PS D:\Users\bala> add-history -inputobject( import-csv
mycmdlets.csv ) -passthru
This command adds the first five commands in the history to
the end of the history list.
PS D:\Users\bala> get-history -id 5 -count 5 |
add-history
Invoke-History
The Invoke-History cmdlet runs commands from the session
history. You can pass objects representing the commands from Get-History to
Invoke-History, or identify commands in the current history by using their ID
number. To find the identification number of a command, use Get-History.
The -iD parameter identifies a command in the history. You
can type the ID number of the command or the first few characters of the
command.
If you omit this parameter, Invoke-History runs the last
(most recent) command.
Examples
Run the 'dir' command first and then execute the following
cmd. This would run the last (most recent) command in the session history. You
can abbreviate this command as "r" (think "repeat" or "rerun"), the alias for
Invoke-History.
PS D:\Users\bala> invoke-history
dir
Directory:
Microsoft.PowerShell.Core\FileSystem::D:\Users\bala
Mode LastWriteTime Length Name
---- -------------
------ ----
d-r-- 23-11-2007 13:25:13 Contacts
d-r-- 25-02-2008 17:42:46 Desktop
d-r-- 24-02-2008 12:29:07
Documents
d-r-- 10-02-2008 14:27:58
Downloads
d-r-- 25-02-2008 17:04:01
Favorites
d-r-- 17-01-2008 16:50:44 Links
This command runs the command in the session history with ID
80. Because the name of the -id parameter is optional, you can abbreviate this
command as "Invoke-History 80", "ihy 80" or "r 80".
PS D:\Users\bala> invoke-history -id 80
get-history -id 2
The following cmdlet produces the same output as in the
example above.
PS D:\Users\bala> get-history -id 80 |
invoke-history
get-history -id 2
This command runs the most recent get-wmiobject command in
the session history.
PS D:\Users\bala> invoke-history -id get-wmi
get-wmiobject win32_service
Export-Console
The Export-Console cmdlet exports the configuration of the
current console to a Windows PowerShell console file (.psc1). You can use this
cmdlet to save a console configuration that you changed by changing its
properties or by adding a Windows PowerShell snap-in to the console.
The parameter -path specifies a path and file name for the
console file (*.psc1). This parameter is required unless you have exported a
console file during the current session. It is also required when you use the
NoClobber parameter to prevent the current console file from being
overwritten.
Examples
This command exports the current console configuration to the
MyConsole.psc1 file in the Consoles subdirectory of the directory stored in
$pshome. By default, $pshome stores the path to the Windows PowerShell
installation directory.
To see the value of this variable on your computer, type
it.
PS D:\Windows\System32> $pshome
D:\Windows\System32\WindowsPowerShell\v1.0
Create a sub-directory named "Consoles" in the $pshome
folder.
PS D:\Windows\System32> md $pshome\consoles
Directory:
Microsoft.PowerShell.Core\FileSystem::D:\Windows\System32\WindowsPowerShell\v1.0
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 29-02-2008 17:49:27 consoles
Now, use the export-console command.
PS D:\Windows\System32> export-console -path
$pshome\Consoles\MyConsole.psc1
See the contents of the myconsole.psc1 file
PS D:\Windows\System32> type
$pshome\Consoles\MyConsole.psc1
<?xml version="1.0" encoding="utf-8"?>
<PSConsoleFile ConsoleSchemaVersion="1.0">
<PSVersion>1.0</PSVersion>
<PSSnapIns />
</PSConsoleFile>
This command exports the current console configuration to the
Windows PowerShell console file in the current directory.
PS D:\Users\bala> export-console -path
MyConsole.psc1
PS D:\Users\bala> type myconsole.psc1
<?xml version="1.0" encoding="utf-8"?>
<PSConsoleFile ConsoleSchemaVersion="1.0">
<PSVersion>1.0</PSVersion>
<PSSnapIns />
</PSConsoleFile>
The following command uses the $ConsoleFilename variable to
find the name of the current console file.
PS D:\Windows\System32> $consolefilename
D:\Windows\System32\WindowsPowerShell\v1.0\Consoles\MyConsole.psc1
Export-Csv
The export-csv creates a comma-separated values (CSV) file
that represents the input objects. EpCsv is the alias for this cmdlet.
Using the -path parameter, specify the path to the CSV to
create. The -inputObject accepts objects that the cmdlet will represents as a
CSV file. Enter a variable that contains the objects or type a command or
expression that gets the objects.
Structure of the CSV file:
If the NoTypeInformation parameter is not specified, the
first line of the CSV file contains the string '#TYPE ' followed by the
fully-qualified name of the type being represented. For example: #TYPE
System.Diagnostics.Process. The next line of the CSV file represents column
headers. It contains a comma-separated list of the names of all the properties
of the first input object. Additional lines of the file contain comma-separated
lists of the values of each of the properties named in the column header line
for each input object.
The first object establishes the column headers. The headers
are not modified in response to subsequent input objects. If those objects do
not include some of the properties in the column header line,two commas are
written to indicate a missing property and ensure proper alignment of property
values with the property names in the column headers.
Property values that contain commas, double quotes, leading
or trailing spaces, or line breaks, are put in double quotes before being
written to the CSV file. Any double quotes contained in a property are redoubled
to indicate that they are literal.
You can use the Import-CSV cmdlet to use the information in
the CSV file to recreate the input objects.
Examples
This command selects a few properties of the notepad process
and exports them to a CSV format file named data.csv.
PS D:\Windows\System32> get-process notepad |
select-object basePriority, ID, SessionID, WorkingSet | export-csv -path
data.csv
PS D:\Windows\System32> type data.csv
#TYPE System.Management.Automation.PSCustomObject
BasePriority,Id,SessionId,WorkingSet
8,2140,1,4677632
The following command first get all service information with
names starting with letter 'v' and export the information to a file named
servicedata.csv
PS D:\Windows\System32> get-service v* | export-csv
-path servicedata.csv
PS D:\Windows\System32> type servicedata.csv
#TYPE System.ServiceProcess.ServiceController
Name,CanPauseAndContinue,CanShutdown,CanStop,DisplayName,DependentServices, MachineName,ServiceName,ServicesDependedOn,S
erviceHandle,Status,ServiceType,Site,Container
vds,False,False,False,"Virtual
Disk",System.ServiceProcess.ServiceController[],.,vds,System.ServiceProcess.ServiceContr
oller[],SafeServiceHandle,Stopped,Win32OwnProcess,,
VSS,False,False,False,"Volume Shadow
Copy",System.ServiceProcess.ServiceController[],.,VSS,System.ServiceProcess.Servic
eController[],SafeServiceHandle,Stopped,Win32OwnProcess,,
Export-Clixml
This cmdlet creates an XML-based representation of an object
or objects and stores it in a file. You can then use the Import-CLIXML cmdlet to
recreate the saved object based on the contents of that file.
The -path parameter specify the path to the file where the
XML representation of the object will be stored. The -inputObject parameter
specify the object to be converted. The -depth parameter specify how many levels
of contained objects should be included in the XML representation. eg. you must
specify a depth of 2 to represent properties in xml file.
Examples
This command creates an XML file that stores a given
string.
PS D:\Windows\System32> "Let this string be stored in
xml file" | export-clixml simple.xml
PS D:\Windows\System32> type simple.xml
<Objs Version="1.1"
xmlns="http://schemas.microsoft.com/powershell/2004/04">
<S>Let this string be stored in xml
file</S>
</Objs>
This command get the information about notepad process and
export it to xml file.
PS D:\Windows\System32> get-process notepad |
export-clixml -path servicedata.xml
PS D:\Windows\System32> type servicedata.xml
<Objs Version="1.1"
xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="RefId-0">
<TN RefId="RefId-0">
<T>System.Diagnostics.Process</T>
<T>System.ComponentModel.Component</T><T>System.MarshalByRefObject</T>
<T>System.Object</T>
</TN>
<Props>
<I32 N="BasePriority">8</I32><B
N="HasExited">false</B><S N="Handle">1052</S>
<I32 N="HandleCount">56</I32>
<I32 N="Id">1412</I32><S
N="MachineName">.</S><S N="MainWindowHandle">852636</S>
<S N="MainWindowTitle">data2 - Notepad</S>
<S N="MainModule">System.Diagnostics.ProcessModule
(NOTEPAD.EXE)</S>
<S N="MaxWorkingSet">1413120</S><S
N="MinWorkingSet">204800</S>
<Obj N="Modules" RefId="RefId-1"><TN
RefId="RefId-1"><T>System.Diagnostics.ProcessModuleCollection</T>
<T>System.Collections.ReadOnlyCollectionBase</T>
<T>System.Object</T></TN><IE><S>System.Diagnostics.ProcessModule
(NOTEPAD.EXE)</S><S>System.Diagnostics.ProcessModule
(ntdll.dll)</S><S>System.Diagnostics.ProcessModule
(kernel32.dll)</S><S>S
ystem.Diagnostics.ProcessModule
(ADVAPI32.dll)</S><S>System.Diagnostics.ProcessModule
(RPCRT4.dll)</S><S>System.Diagnos
tics.ProcessModule
(GDI32.dll)</S><S>System.Diagnostics.ProcessModule
(USER32.dll)</S><S>System.Diagnostics.ProcessModu
le
(msvcrt.dll)</S><S>System.Diagnostics.ProcessModule
(COMDLG32.dll)</S><S>System.Diagnostics.ProcessModule (SHLWAPI.d
ll)</S><S>System.Diagnostics.ProcessModule
(COMCTL32.dll)</S><S>System.Diagnostics.ProcessModule
(SHELL32.dll)</S><S>Sy
stem.Diagnostics.ProcessModule
(WINSPOOL.DRV)</S><S>System.Diagnostics.ProcessModule
(ole32.dll)</S><S>System.Diagnosti
cs.ProcessModule
(OLEAUT32.dll)</S><S>System.Diagnostics.ProcessModule
(IMM32.DLL)</S><S>System.Diagnostics.ProcessModu
le
(MSCTF.dll)</S><S>System.Diagnostics.ProcessModule
(LPK.DLL)</S><S>System.Diagnostics.ProcessModule
(USP10.dll)</S><
S>System.Diagnostics.ProcessModule
(uxtheme.dll)</S><S>System.Diagnostics.ProcessModule
(CLBCatQ.DLL)</S></IE></Obj><I3
2 N="NonpagedSystemMemorySize">2592</I32><I64
N="NonpagedSystemMemorySize64">2592</I64><I32
N="PagedMemorySize">1429504
</I32><I64
N="PagedMemorySize64">1429504</I64><I32
N="PagedSystemMemorySize">42368</I32><I64
N="PagedSystemMemorySize64
">42368</I64><I32
N="PeakPagedMemorySize">1429504</I32><I64
N="PeakPagedMemorySize64">1429504</I64><I32 N="PeakWorkingS
et">4923392</I32><I64
N="PeakWorkingSet64">4923392</I64><I32
N="PeakVirtualMemorySize">41558016</I32><I64 N="PeakVirtua
lMemorySize64">41558016</I64><B
N="PriorityBoostEnabled">true</B><S
N="PriorityClass">Normal</S><I32 N="PrivateMemorySi
ze">1429504</I32><I64
N="PrivateMemorySize64">1429504</I64><TS
N="PrivilegedProcessorTime">PT1.171875S</TS><S N="Proces
sName">notepad</S><S
N="ProcessorAffinity">3</S><B
N="Responding">true</B><I32 N="SessionId">1</I32><S
N="StartInfo">Sy
stem.Diagnostics.ProcessStartInfo</S><DT
N="StartTime">2008-02-29T18:26:15.913978+05:30</DT><Nil
N="SynchronizingObject
" /><Obj N="Threads" RefId="RefId-2"><TN
RefId="RefId-2"> <T>System.Diagnostics.ProcessThreadCollection</T><T>System.Col
lections.ReadOnlyCollectionBase</T><T>System.Object</T></TN><IE> <S>System.Diagnostics.ProcessThread</S></IE></Obj><TS
N
="TotalProcessorTime">PT2.015625S</TS><TS
N="UserProcessorTime">PT0.84375S</TS><I32
N="VirtualMemorySize">41558016</I32
><I64
N="VirtualMemorySize64">41558016</I64><B
N="EnableRaisingEvents">false</B><I32
N="WorkingSet">4923392</I32><I64 N
="WorkingSet64">4923392</I64><Nil N="Site"
/><Nil N="Container" /></Props></Obj></Objs>
Export-Alias
This cmdlet exports information about currently-defined
aliases within a specified namespace scope to a file. If the output file
specified does not exist, the cmdlet will create it. It can export the alias
information to comma-separated value(CSV) format or script (Script) format. EpAl
is the alias for this cmdlet.
Structure of the File
The exported file includes the following header information
preceded by the # comment symbol: Alias File, Exported by, Date/Time and
Machine. The CSV format includes the name of the alias, the name of the
corresponding cmdlet, the description of the alias if there is one, and the
scope. The Script format includes the same information, but provides it as a
set-alias command with the alias information provided as the value of the
parameters to Set-Alias.
The -path specifies the path to the file in which to store
alias information. The -name specifies the names of the aliases to export.
Examples
This command exports current alias information to a file
named myalias.txt in the current directory.
PS D:\Users\bala> export-alias -path myalias.txt
PS D:\Users\bala> type myalias.txt
# Alias File
# Exported by : bala
# Date/Time : 03 March 2008 11:53:17
# Machine : BALAMURALI-B
"ac","Add-Content","","ReadOnly, AllScope"
"asnp","Add-PSSnapin","","ReadOnly, AllScope"
"clc","Clear-Content","","ReadOnly, AllScope"
"cli","Clear-Item","","ReadOnly, AllScope"
"clp","Clear-ItemProperty","","ReadOnly, AllScope"
"clv","Clear-Variable","","ReadOnly, AllScope"
"cpi","Copy-Item","","ReadOnly, AllScope"
"cpp","Copy-ItemProperty","","ReadOnly, AllScope"
"cvpa","Convert-Path","","ReadOnly, AllScope"
"diff","Compare-Object","","ReadOnly, AllScope"
"epal","Export-Alias","","ReadOnly, AllScope"
This command exports current alias information to a file
named alias.txt. It includes a description in the header comment of the file and
appends the exported information if the file named alias.txt exists and has
content.
PS D:\Users\bala> export-alias -path alias.txt -append
-description "Alias infomation file"
PS D:\Users\bala> notepad alias.txt
# Alias File
# Exported by : bala
# Date/Time : 03 March 2008 11:55:52
# Machine : BALAMURALI-B
#
# Alias infomation file
"ac","Add-Content","","ReadOnly, AllScope"
"asnp","Add-PSSnapin","","ReadOnly, AllScope"
"clc","Clear-Content","","ReadOnly, AllScope"
"cli","Clear-Item","","ReadOnly, AllScope"
"clp","Clear-ItemProperty","","ReadOnly, AllScope"
"clv","Clear-Variable","","ReadOnly, AllScope"
"cpi","Copy-Item","","ReadOnly, AllScope"
"cpp","Copy-ItemProperty","","ReadOnly, AllScope"
This command exports current alias information to a file
named alias.txt. It overwrites any previous contents in that file if it exists.
The alias information is exported as a series of commands that use the Set-Alias
cmdlet. In the second line, the command opens the resulting exported file using
Notepad.
PS D:\Users\bala> export-alias -path alias.txt -as
script
PS D:\Users\bala> notepad alias.txt
# Alias File
# Exported by : bala
# Date/Time : 03 March 2008 12:00:35
# Machine : BALAMURALI-B
set-alias -Name:"ac" -Value:"Add-Content" -Description:""
-Option:"ReadOnly, AllScope"
set-alias -Name:"asnp" -Value:"Add-PSSnapin"
-Description:"" -Option:"ReadOnly, AllScope"
set-alias -Name:"clc" -Value:"Clear-Content"
-Description:"" -Option:"ReadOnly, AllScope"
set-alias -Name:"cli" -Value:"Clear-Item" -Description:""
-Option:"ReadOnly, AllScope"
set-alias -Name:"clp" -Value:"Clear-ItemProperty"
-Description:"" -Option:"ReadOnly, AllScope"
set-alias -Name:"clv" -Value:"Clear-Variable"
-Description:"" -Option:"ReadOnly, AllScope"
set-alias -Name:"cpi" -Value:"Copy-Item" -Description:""
-Option:"ReadOnly, AllScope"
set-alias -Name:"cpp" -Value:"Copy-ItemProperty"
-Description:"" -Option:"ReadOnly, AllScope"
Import-Alias
This cmdlet is used to import an alias list from a file.
The -path parameter specifies the path to a file that
includes exported alias information. Wildcards are allowed but they must resolve
to a single name.
Example
To see how this cmdlet works, use the following cmdlets and
instructions carefully.
1) Create a new alias "listallfiles" for the dir cmdlet.
PS D:\Users\bala> set-alias listallfiles dir
2) Issue the Export-alias cmdlet to export all the aliases to
a text file.
PS D:\Users\bala> export-alias newaliases.txt
3) In the newaliases.txt, remove all the lines except the
alias you just created.
# Alias File
# Exported by : bala
# Date/Time : 07 March 2008 19:01:18
# Machine : BALAMURALI-B
"listallfiles","dir","","None"
4) Now, Exit from the Windows PowerShell command console and
re-open the console.
5) Import the alias info from a file newaliases.txt
PS D:\Users\bala> import-alias newaliases.txt
6) Run the alias and see the output for the dir cmdlet.
PS D:\Users\bala> listallfiles
Import-Csv
This cmdlet imports comma-separated value (CSV) files in the
format produced by the Export-CSV cmdlet and returns objects that correspond
to the objects represented in that CSV file.
You must supply the path to the CSV file to import in the
-path parameter
Example
This command imports the history.csv file, once created
using the export-csv command and it is piped output the $helper. On running the
$helper, you would see the cmdlets re-executed.
PS D:\Users\bala> $helper = import-csv history.csv
PS D:\Users\bala> $helper
Id : 3
CommandLine : help add-history
ExecutionStatus : Completed
StartExecutionTime : 26-02-2008 18:53:23
EndExecutionTime : 26-02-2008 18:53:24
Id : 4
CommandLine : help get-history
ExecutionStatus : Completed
StartExecutionTime : 26-02-2008 18:53:51
EndExecutionTime : 26-02-2008 18:53:52
Id : 5
CommandLine : help get-history -detailed
ExecutionStatus : Completed
StartExecutionTime : 26-02-2008 18:54:00
EndExecutionTime : 26-02-2008 18:54:02
Id : 6
CommandLine : get-histroy
ExecutionStatus : Completed
StartExecutionTime : 26-02-2008 18:59:29
EndExecutionTime : 26-02-2008 18:59:29
Id : 7
CommandLine : get-history
ExecutionStatus : Completed
StartExecutionTime : 26-02-2008 18:59:33
EndExecutionTime : 26-02-2008 18:59:33
Import-Clixml
This cmdlet imports a CLIXML file and creates corresponding
objects within Windows PowerShell.
The -path parameter specify the location of the XML files to
be converted into PSObjects.
Example
This command uses the Export-Clixml cmdlet to save a
serialized copy of the notepad process information returned by Get-Process. It
then uses Import-Clixml to retrieve the contents of the serialized file and
recreate an object that is stored in the $notepad variable.
PS D:\Users\bala> get-process notepad | export-clixml
mynote.xml
After exporting to the xml file, see the content.
PS D:\Users\bala> type mynote.xml
<Objs Version="1.1"
xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="RefId-0">
<TN RefId="RefId-0">
<T>System.Diagnostics.Process</T>
<T>System.ComponentModel.Component</T>
<T>System.MarshalByRefObject</T>
<T>System.Object</T>
</TN>
.........................
.........................
.........................
Now, import the xml file content to a variable.
PS D:\Users\bala> $notepad = import-clixml
mynote.xml
When you check $notepad variable, you get the process
information as expected.
PS D:\Users\bala> $notepad
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id
ProcessName
------- ------ ----- ----- ----- ------ --
-----------
195 7 8044 13140 76 2.33 2632
notepad
Out-Null
This cmdlet deletes the output. Instead of sending it to the
console, it sends output to NULL.
The -inputObject parameter specify the object that sent to
null (deleted). Enter a variable that contains the objects or type a command or
expression that gets the objects.
Example
This command gets the items in the local directory, but then
discards them, instead of passing them through the pipeline or displaying them
at the command line. This is useful for discarding output that you don't
need.
PS D:\Users\bala> get-childitem
Directory:
Microsoft.PowerShell.Core\FileSystem::D:\Users\bala
Mode LastWriteTime Length Name
---- ------------- ------ ----
d-r-- 23-11-2007 13:25:13 Contacts
d-r-- 06-03-2008 20:36:51 Desktop
d-r-- 07-03-2008 07:09:22 Documents
............
............
PS D:\Users\bala> get-childitem | out-null
PS D:\Users\bala>
As you see above, it returns no output.
|