1. Format-List
2. Format-Table
3. Format-Wide
4. Format-Custom
Posted Date:- 2021-11-27 12:34:07
Copy-Item is a command which is used to copy the files or folders in a file system drive and the registry keys in the registry drive.
Posted Date:- 2021-11-27 12:33:09
Comparison Operators are used in PowerShell for comparing the values. Following are four types of comparison operators:
1. Equality Comparison Operator
2. Match Comparison Operator
3. Containment Comparison Operator
4. Replace Comparison Operator
Posted Date:- 2021-11-27 12:32:19
The query gets data from the Application log to build the hash table one key-value pair at a time. The query gets data from the Application log. The hash table is equivalent to <Get-WinEvent –LogName Application>.
To begin, create the <Get-WinEvent> query. Use the FilterHashtable parameter’s key-value pair with the key, LogName, and the value, Application.
Example:
>Get-WinEvent -FilterHashtable @{
LogName=’Application’
}
–complete–
Posted Date:- 2021-11-27 12:31:22
Local general user information — number of licensed users, current no. of users, and the owner name — can be found with a selection of “Win32_OperatingSystem†class properties. You can select the properties to display like this:
Example:
>Get-CimInstance -ClassName Win32_OperatingSystem |
Select-Object -Property NumberOfLicensedUsers,NumberOfUsers,RegisteredUser
Posted Date:- 2021-11-27 12:30:47
To list all installed hotfixes by using Win32_QuickFixEngineering:
Example:
Get-CimInstance -ClassName Win32_QuickFixEngineering
Posted Date:- 2021-11-27 12:30:15
The following command collects information about the desktops on the local computer:
Example:
>Get-CimInstance -ClassName Win32_Desktop
Posted Date:- 2021-11-27 12:28:24
Enums support arithmetic operations, as shown in the following example.
Example:
>enum SomeEnum { Max = 42 }
>enum OtherEnum { Max = [SomeEnum]::Max + 1 }
Posted Date:- 2021-11-27 12:27:16
If attempt to delete the <HKCU:CurrentVersion subkey> :
Example:
>Remove-Item -Path HKCU:CurrentVersion
(To delete contained items without prompting, specify the Recurse parameter )
>Remove-Item -Path HKCU:CurrentVersion –Recurse
If you wanted to remove all items within HKCU:CurrentVersion but not <HKCU:CurrentVersion> itself, you could instead use:
>Remove-Item -Path HKCU:CurrentVersion* -Recurse
Posted Date:- 2021-11-27 12:26:45
Deleting items is essentially the same for all providers. The following commands will silently remove items:
Example:
>Remove-Item -Path HKCU:Software_custom
>Remove-Item -Path ‘HKCU:key with spaces in the name’
Posted Date:- 2021-11-27 12:26:04
Creating new keys in the registry is simpler than creating a new item in a file system. Because all registry keys are containers, you do not need to specify the item type; you simply supply an explicit path, such as:
Example:
>New-Item -Path HKCU:Software_custompath
Posted Date:- 2021-11-27 12:25:36
There are so many predefined variables in PowerShell, which are known as the automatic variables. These variables mainly store the information about the PowerShell, and created and maintained by the PowerShell. Any user can't change or update the value of these variables.
Following are some common automatic variables:
* $$
* $?
* $^
* $_
* $args
* $Error
* $foreach
* $Home
* $input
* $null
* $PSHome
* $PWD
Posted Date:- 2021-11-27 12:24:27
Declaration: In PowerShell, you can declare a variable by using the $ (dollar) sign at the beginning of the variable name. Following syntax describes how to declare the variable:
$ <variable_name>
For example: $var
Creation or Initialization: In PowerShell, you can create a variable by assigning the value to a variable using the assignment operator. Following syntax describes how to declare the variable:
$ <variable_name> = <value>
Posted Date:- 2021-11-27 12:23:17
The example given finds the value of DevicePath in <HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion>.
Using <Get-ItemProperty>, use the Path parameter to specify the name of the key, and Name parameter to specify the name of the DevicePath entry.
Example:
>Get-ItemProperty -Path HKLM:SoftwareMicrosoftWindowsCurrentVersion -Name DevicePath
Posted Date:- 2021-11-27 12:22:37
To view the registry entries in a more readable form, use “Get-ItemPropertyâ€:
Example:
>Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion
Posted Date:- 2021-11-27 12:21:58
To see the names of the entries in the registry key <HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersion>, use <Get-Item>. Registry keys have property with the generic name of “Property†which is a list of registry entries in the key. The command given below selects the Property property and expands the items so that they are displayed in a list:
Example:
>Get-Item -Path Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion |
>Select-Object -ExpandProperty Property
Posted Date:- 2021-11-27 12:21:33
The Get-Content cmdlet command can be used to read an entire file in one step and one element per line of the file content. You can confirm it by checking the length of the content returned :
Example :
PS> Get-Content -Path C:sampledata.txt
PS> (Get-Content -Path C: sampledata.txt).Length
6
Posted Date:- 2021-11-27 12:21:09
Using the <â€New-PSDriveâ€> command. The following command will create a local drive P: rooted in the local Program Files directory which is visible only from the PowerShell session:
Example:
>New-PSDrive -Name P -Root $env:ProgramFiles -PSProvider FileSystem
Posted Date:- 2021-11-27 12:20:43
If you don’t want to be prompted for each and every contained item, specify the Recurse parameter:
Example:
>Remove-Item -Path C: empNewFolder –Recurse
Posted Date:- 2021-11-27 12:20:03
* PowerShell which requires DotNet framework which is cost-effective.
* Security-Risks.
* It depends on the webserver to execute. Which may not right thing for any client. This leads to additional space on a server so custom software Development Company does not allow to afford resources for this.
Posted Date:- 2021-11-27 12:19:35
This following examle shows how to create a <Where-Object> command with multiple-conditions.
This command gets non-core modules which support the Updatable <Help> features. It uses the <ListAvailable> parameter of the Get-Module> command to get every modules on the system. A pipeline operator (|) sends the modules to the <Where-Object> command , that gets modules whose names do not start with Microsoft or PS, and have a value for the <HelpInfoURI> property, that tells the powerShell where to find updated help files for the module. The compare-statements are connected by the <And> logical operator.
Example:
>Get-Module -ListAvailable | where {($_.Name -notlike “custom*†-and $_.Name -notlike “PS*â€) -and $_.HelpInfoUri}.
Posted Date:- 2021-11-27 12:18:10
The command processes that have a <ProcessName> property value that begins with the letter-p. The Match-operator use the regular expression matches. The scriptblock and statement syntax are same and used interchangeably.
Example:
>Get-Process | Where-Object {$_.ProcessName -Match “^p.*â€}
>Get-Process | Where-Object ProcessName -Match “^p.*â€
Posted Date:- 2021-11-27 12:17:45
Try: It is a part of a script where we want the PowerShell to monitor the errors. If an error occurs in this block, the automatic variable $Error stores the error. And then, the PowerShell searches the Catch block to handle the error.
Catch: In a PowerShell script, it is a part which handles the errors generated by the Try block.
Finally: In a PowerShell script, it is a part which releases the resource that no longer needed by a script.
Posted Date:- 2021-11-27 12:17:15
The <PSSessions> command that are connected to the local system. To specify the local system, type the system name, <localhost>, or a dot (.)
The command returns all of the sessions on the local system, even if they were created in different sessions or on different systems.
Posted Date:- 2021-11-27 12:16:38
The <Get-PSSession> command gets the user-managed sessions (PSSessions) from powershell on local and remote computers.
Example:
>Get-PSSession
Posted Date:- 2021-11-27 12:16:18
This “Get-Job†command gets only those jobs that are created but haven’t yet been started. It includes the jobs that are scheduled the jobs to run in the future slots and those not yet scheduled.
Example:
>Get-Job -State NotStarted
Posted Date:- 2021-11-27 12:16:02
Example to save the history in Historysave.csv file as below:
This example iterate the five most recent history entries. The pipeline passes the entire result to the <Export-Csv> command, which formats the history as comma-separated text and saves it in the Historysave.csv file. The file contains the data that is showed when you format the history as a list. This includes the status and begin/start and end times of the command.
>Get-History -ID 3 -Count 5 | Export-Csv Historysave.csv
Posted Date:- 2021-11-27 12:15:26
The <Get-History> command gets the session’s history, (i.e.) the list of commands entered during the present session.
The PowerShell routinely preserves a history of each session. The number of command entries within the session history is decided by the worth of the <$MaximumHistoryCount> preference variable. At start in Windows PowerShell 3.0, the default value is <4096>. By default-, history of files are saved within the home directory, but you’ll save the entire file in any location.
Example:
>Get-History
Posted Date:- 2021-11-27 12:15:03
These following examples display the selected portions of the Format-Table command help.
>Get-Help Format-Table -Examples
>Get-Help Format-Table -Parameter *
>Get-Help Format-Table -Parameter GroupBy
The examples parameter displays the the assistance file’s NAME and SYNOPSIS sections, and every one the examples. You can’t identify an example number because the examples parameter is a switch parameter.
The Parameter shows only the content description of the parameters. If you specify only the asterisk-(*) wildcard character, it shows the descriptions of every/all parameters. When Param specifies a parameter name such as <GroupBy>, info (information) about that parameter is shown.
Posted Date:- 2021-11-27 12:14:42
The command “Get-Help†displays the information about PowerShell concepts and commands functionality, together with <cmdlets>, functions, Common Information Model-(CIM) commands, -workflows, -providers, -aliases, and the scripts.
To get the help content for a given PowerShell cmdlet, type Get-Help follow by the _cmdlet_ name, such as: <“Get-Helpâ€>, <“Get-Processâ€>.
Example:
>Get-Help Format-Table
>Get-Help -Name Format-Table
Posted Date:- 2021-11-27 12:14:14
There are two ways to do this
* get-wmiobject win32_service l where-object {$_.name-like “*sql*â€}
* get-service sql*
Posted Date:- 2021-11-27 12:13:39
Get-WmiObject-Class Win32_Product- ComputerName . l Format-wide-column1.
Posted Date:- 2021-11-27 12:13:14
The $input variable enables a function to access data coming from the pipeline.
Posted Date:- 2021-11-27 12:12:57
To rename a variable,
Rename-Item- Path Env: MyVariable –NewName MyRenamedVar
Posted Date:- 2021-11-27 12:12:39
To convert the object into HTML
Get-Process l Sort-object – property CPU –descending l convert to – HTML l Out-file “process.htmlâ€
Posted Date:- 2021-11-27 12:12:20
To get all child folders in a specific folder, you have to use parameter recurse in the code.
Get-ChildItem C:Scripts –recurse
Posted Date:- 2021-11-27 12:11:49
The use of Array in PowerShell is to run a script against remote computers. In order to create an array, you have to create a variable and assign the array. Arrays are represented by “@â€symbol, they are represented as hashtable but not followed by curly braces.
For example, $arrmachine = @ ( “machine1†, “machine2†, “machine3â€)
Posted Date:- 2021-11-27 12:11:31
Again, this is basic stuff. I would not get caught up in ideology, the good old ping. Exe is seamlessly valid, as long as the candidate knows the option to specify 5 packets.
If you really want the more “PowerShell†<Test-Connection>, then just want the command to return <$True> if the ping is successful connected and <$False> if it is not connected.
Posted Date:- 2021-11-27 12:10:49
The command “ConvertTo-CSV†is a one stage process that changes data into csv format and let it persist inside the shell “Export-CSV†is a 2 step process that not only changes data into “CSV†and also writes the output to a “CSV†format file.
Posted Date:- 2021-11-27 12:10:28
The command is as follows:
Get-Content env:psmodulepath
Posted Date:- 2021-11-27 12:10:13