'|'
operator. In a command, each pipeline operator is used to send the output or result of the preceding command to the next command.Command-1 | Command-2 | Command-3
()
Parentheses Brackets in compulsory arguments.{}
Braces Brackets for blocked statements[]
Square Brackets. These brackets specify optional items.Get-Command
cmdlet included in PowerShell is used to get all the cmdlets that are registered in the command shell. The verb identifies the action that the cmdlet performs, and the noun identifies the resource on which the cmdlet performs its action.VS2010
, SharePoint components can be deployed with the help of ctrl+f5
. Features of the web part can be activated through the PowerShell script.
=
” sign for declaring variables. Likewise, there are other operators like –ne for “not equal
” , -gt ( greater than )
or –lt (less than)
. E
and K
, then the get-command would look like - get-command [ E–K ]*
L
and R
then your PowerShell get-command
will be like# PowerShell Get - Command Range
Clear-Host
Get-Command [ L–R ]*
# PowerShell Map Network Drive
$Net = $( New - Object – ComObject Wscript.Network )
$Net.MapNetworkDrive( "D:", \\expert\FTL901 )
In here the drive letter is “D:” and the Network share is called ‘expert’ on a computer called ‘FTL901.’
-query
’ to introduce a classic ‘Select * from
’ a phraseSelect
’ in PowerShell is Select-String
. This cmdlet checks for a word, phrase or any pattern matchSelect Object
$Error
stores the error. And then, the PowerShell searches the Catch block to handle the error.key-value
”. Here, both “key
”, as well as “value
”, might comprise any length and data. In order to declare hash table users will have to apply @
in front of curly braces. @
” symbol and illustrated as a hashtable.$arrmachine = @ ( “machine1” , “machine2” , “machine3”)
PowerShell | Command Prompt (CMD) |
---|---|
1. It is a task-based command-line shell and associated scripting language which is based on the .NET framework. | 1. It is the default command-line interpreter for the Microsoft Windows Operating System. |
2. It can interpret both the commands of a batch and PowerShell. | 2. It can interpret only the commands of a batch. |
3. It controls and automates the Windows operating system and applications on a Windows server. | 3. It executes the commands which are specified on the console to debug the problem. |
4. The output generated by the PowerShell is not just a stream of characters (text) but a collection of objects. | 4. The output generated by the command prompt is just a stream of characters (text). |
5. It is both a shell and scripting environment which supports the creation of large files for managing the windows operating system. | 5. It is just a shell environment, which allows a user to do only easy and basic scripts for the execution of the batch file. |
(hash) #
symbol at the beginning of each line".<Any Command or statement> # <Any comment>
# (hash)
symbol at the end of last line and beginning of the first line".<# Multiple-line Comment.........................
....................
................................................#>
Statement-1
Statement-2
Statement-N
win32_computersystem.
PS C:> $server = gwmi -cl win32_computersystem
PS C:> $server.SystemType X86-based PC
CIM | Old WMI | New WMI |
---|---|---|
CIM is a Vendor-neutral and industry-standard designed way of manifestation of management information. | Old WMI is Microsoft’s initial incorporation of CIM. | New WMI was released alongside WMF v3 in the year 2012 and it was compliant to the latest CIM standards. |
It is designed by another company named the DMTF | It is designed by Microsoft | It is designed by Microsoft as well. |
It not available | It is available in PowerShell v1 | It is available in PowerShell v3. |
It employs WSMan which is a standard developed by DMTF. | It used DCOM and RPCs Remote Procedure Calls. | It employs WSMan and no more DCOM errors are possible with this. |
It can work on any platform. | Works on Windows only. | Works on Windows only. |
It owns WSMan Port – 5985 (HTTP) and 5986(HTTPS) for its purpose. | It has RPC port- 135 for use | It owns WSMan Port – 5985 (HTTP) and 5986(HTTPS) for use. |
if ( $i -eq 1)
{
## Do something
}
Else
{
## Do something
}
switch ($i) {
0
{
Write-Host “I is 0”
}
1
{
Write-Host “I is 0”
}
Default
{
Write-Host “I is 0”
}
}
while ($i -eq 0) {
## do something
}
do {
## do something
} while ($i -lt 0)
$array = ( ‘item1’ , ‘item2’ , ‘item3’)
foreach ($item in $array) {
}
for ($i = 0; $i -lt 5; $i++)
{
$i
}
integers
, strings
, and objects
. $ (dollar)
sign at the beginning of the variable name. Following syntax describes how to declare the variable :$ <variable_name>
$var
$ <variable_name> = <value>
$
: This variable includes the last token available in the last line that is received by the session.$?
: This variable may include the completion status of the last operation. If the last operation succeeded, its value is TRUE
and FALSE
if it has failed.$^
: It may include the first token of the last line obtained by the session.$Args
: Includes a collection of the undeclared parameters or parameter values. These are handed over to a script, script block, or function. When you construct a function, you can display the parameters by making use of the param keyword or by incorporating a comma-separated list of parameters in parentheses just after the function name.$Error
: This variable includes an array of error objects that represent the most recent errors. The current mistake is the first error object in the array ($Error[0]
).$ForEach
: This variable includes the enumerator (not the resulting values) of a ForEach loop. You can make use of the properties and processes of enumerators on the value of the $ForEach
variable. This variable lives only while the ForEach loop is operating; it gets deleted post the completion of the loop.$Home
: This variable includes the full path of the customer’s home directory. This variable is the counterpart of the %homedrive%%homepath%
environment variables, commonly known as C:\Users<UserName>
.$OFS
: $OFS
is a remarkable variable that saves a string (Series of characters) that you wish to utilize as an output field separator. Employ this variable when you are transforming an array into a string. By default, the value of $OFS
is " "
, but you can modify the value of $OFS
in your session, by just typing $OFS="<value>"
. If you are anticipating the default value of " "
in your module, script, or configuration output, be mindful that the $OFS
default value has not been modified anywhere in your code.unblocked
, like utilizing the Unblock-File
cmdlet..ps1xml
), PowerShell profiles (.ps1
), and module script files (.psm1
) formattingnon-Windows
systems and cannot be modified.