Out of the box, Windows PowerShellver 1.0 has already
been available in the industry i am going to bring you a PS command and its
usage and I hope that readers would allocate some time to read and use it at
their leisure. It’s a sort of learning by fun!
The main ingredients of PowerShell are Aliases, Cmdlets,
Providers(FileSystem, Security System, EventLog, Windows Intrumentation)
The built-in commands with Windows Powershell are called
Cmdlets. A cmdlet is a single-feature, built-in command by which an
operation is completed. Cmdlets include even the much familiar command line DOS
commands.
To execute commands, click on the Windows PowerShell
program in the Start menu that opens up a command window. Type the command and
press enter.
[For those who have not installed PowerShell in their
systems, you can get the downloaded here.
To be more clear and simple, the full syntax of the
command is not going to be included. Learning by Example!
This tutorial will help us understand all the available
Powershell commands available.
ac
This command is used to add content to any existing item
or file. ac stands for add content.
Example:
The commands below adds a text to the specified
file.
PS D:\Users\bala> ac bb.txt -value "Welcome PowerShell
Add content command"
PS D:\Users\bala> ac bb.txt -value "Welcome
PowerShell"
PS D:\Users\bala> ac documents\my_training_topics.txt
-value "Windows PowerShell"
Windows Services! Imagine where you go in your desktop
to find the right menu or command to open up that Services Dialog listing all of
those server components and their running status.
With Windows PowerShell, you just do it right away with
your command windows and type in few words(cmdlet or mantra), you get a full
control over starting, stopping or any action on a specified service
component.
sasv
This command is used to start one or more than one
stopped services. Alternatively, you can type start-service instead of sasv.
The Start-Service cmdlet sends a start message to the
Windows Service Controller for each of the specified services. If a service is
already running, the message is ignored without error. You can specify the
services by their service names or display names, or you can use the InputObject
parameter to supply a service object representing the services that you want to
start.
Examples:
The commands below starts fax service in variety of
ways.
PS D:\Users\bala> start-service -name Fax
PS D:\Users\bala> start-service -displayname Fax
PS D:\Users\bala> start-service Fax
PS D:\Users\bala> sasv Fax
select-string
The select-string cmdlet identifies patterns in
strings using the value of the Pattern parameter as a regular expression and
matches input against it. You may use SimpleMatch parameter also to find the
string specified in the Pattern parameter as a substring of the input.
The cmdlet is also used to search string content from
files.
Examples:
By specifying the path and pattern, you can get a list
of files and content that matches the pattern.
PS D:\Users\bala> select-string -path documents\*.txt
-pattern ".net"
documents\My_training_topics.txt:3:C# and .NET Framework
2.0, 3.0
documents\My_training_topics.txt:4:ASP.NET 2.0 and AJAX
documents\vs.netVSvb6.txt:5:As you all know, Visual studio
.NET has gone through different versions and today with its
v3.5 wearing all sorts of hats like colorful WPF, vibrant
workflows, connecting Services(WCF) and alerting AJAX, has d
efinitely leaped into a strong and steady place in the
minds of developing community. The easeness and integration of d
ifferent technologies has come to a new level in the new
version of Visual Studio and it is for sure that .NET users, i
n particular, will benefit most of it.
documents\vs.netVSvb6.txt:9:But the legacy Visual Basic 6.0
doesn't seemed to leave VS as it is and still striving for
a better adaptation and prominent place in the IDE. And
also, Visual Studio doesn't seemed to forget its ancestor mantr
as and always willing to give a place for the Guru. Many
developers need not have time to think about this shake-hand r
elationship between VS.NET and VB6. Whether is it for VB6
battling to find a place in VS.NET, or VS.NET needs the Guru
for the guidance, developers are happy to see them walking
together all around the technical spots in 2008, after almos
t half a decade.
documents\vs.netVSvb6.txt:31:<h2>Note</h2> This
control works only when the printer is connected to the system network/
local.
Given a list of strings as input, you can filter them by
specifying the pattern.
PS D:\Users\bala> "VB.NET", "ASP.NET", "XML", "C#.NET" |
select-string -pattern ".net"
VB.NET
ASP.NET
C#.NET
Redirect the output of the dir command and then filter only
files and folders starting with "Do".
PS D:\Users\bala> dir | select-string "Do"
Documents
test-path
The Test-Path cmdlet determines whether all elements
of the path exist. It returns "true" ($true) if all elements exist and "false"
($false) if any are missing.
The main parameters are -path, that specifies a path to
be tested and -pathType that determines the type of element that the path
locates. Returns TRUE if the element is of the specified type and FALSE if it is
not.
Valid values are:
-- Container: An element that contains other
elements, such as a directory or registry key.
-- Leaf: An element that does not contain
other elements, such as a file or registry entry.
-- Any: Either a container or a leaf.
The following lists the acceptable values for this
parameter:
The -isValid parameter determines whether the syntax of
the path is correct.
.
Examples:
The following command checks if d:\bala folder exists.
PS D:\Users\bala> test-path -path d:\bala
True
The following command check if d:\bala\downloads folder
exists
PS D:\Users\bala> test-path -path d:\bala\downloads
False
The following cmdlet checks if d:\bala\documents exists.
PS D:\Users\bala> test-path -path d:\bala\documents
True
The following cmdlet checks if any file in d:\bala\documents
folder except with .doc extension
PS D:\Users\bala> test-path d:\bala\documents\*
-exclude "*.doc"
True
The following cmdlet checks if a given path is a file
PS D:\Users\bala> test-path d:\bala\documents -pathtype
leaf
False
The following cmdlet checks if a given path is a folder.
PS D:\Users\bala> test-path d:\bala\documents -pathtype
container
True
|