Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions reference/3.0/Microsoft.PowerShell.Core/Add-History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
ms.date: 06/09/2017
schema: 2.0.0
locale: en-us
Expand All @@ -7,37 +7,44 @@ online version: http://go.microsoft.com/fwlink/?LinkID=113279
external help file: System.Management.Automation.dll-Help.xml
title: Add-History
---

# Add-History

## SYNOPSIS

Appends entries to the session history.

## SYNTAX

```
Add-History [[-InputObject] <PSObject[]>] [-Passthru] [<CommonParameters>]
```

## DESCRIPTION

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 the Get-History cmdlet to get the commands and pass them to **Add-History**, or you can 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.

## EXAMPLES

### Example 1

```
PS C:\> get-history | export-csv c:\testing\history.csv
PS C:\> import-csv history.csv | add-history
PS> get-history | export-csv c:\testing\history.csv
PS> import-csv history.csv | add-history
```

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 History.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 History.csv file.
The pipeline operator passes the objects to the **Add-History** cmdlet, which adds the objects representing the commands in the History.csv file to the current session history.

### Example 2

```
PS C:\> import-clixml c:\temp\history.xml | add-history -passthru | foreach-object -process {invoke-history}
PS> import-clixml c:\temp\history.xml | add-history -passthru | foreach-object -process {invoke-history}
```

This command imports commands from the History.xml file, adds them to the current session history, and then executes the commands in the combined history.
Expand All @@ -48,38 +55,46 @@ The PassThru parameter passes the objects representing the added commands down t

The command then uses the ForEach-Object cmdlet to apply the Invoke-History command to each of the commands in the combined history.
The **Invoke-History** command is formatted as a script block (enclosed in braces) as required by the **Process** parameter of the **ForEach-Object** cmdlet.

### Example 3

```
PS C:\> get-history -id 5 -count 5 | add-history
PS> get-history -id 5 -count 5 | add-history
```

This command adds the first five commands in the history to the end of the history list.
It uses the Get-History cmdlet to get the five commands ending in command 5.
The pipeline operator (|) passes them to the **Add-History** cmdlet, which appends them to the current history.
The **Add-History** command does not include any parameters, but Windows PowerShell associates the objects passed through the pipeline with the **InputObject** parameter of ** Add-History**.

### Example 4

```
PS C:\> $a = import-csv c:\testing\history.csv
PS C:\> add-history -inputobject $a -passthru
PS> $a = import-csv c:\testing\history.csv
PS> add-history -inputobject $a -passthru
```

These commands add the commands in the History.csv file to the current session history.
The first command uses the Import-Csv cmdlet to import the commands in the History.csv file and store its contents in the variable $a.
The second command uses the **Add-History** cmdlet to add the commands from History.csv to the current session history.
It uses the **InputObject** parameter to specify the $a variable and the **PassThru** parameter to generate an object to display at the command line.
Without the **PassThru** parameter, the **Add-History** cmdlet does not generate any output.

### Example 5

```
PS C:\> add-history -inputobject (import-clixml c:\temp\history01.xml)
PS> add-history -inputobject (import-clixml c:\temp\history01.xml)
```

This command adds the commands in the History01.xml file to the current session history.
It uses the **InputObject** parameter to pass the results of the command in parentheses to the **Add-History** cmdlet.
The command in parentheses, which is executed first, imports the History01.xml file into Windows PowerShell.
The **Add-History** cmdlet then adds the commands in the file to the session history.

## PARAMETERS

### -InputObject

Adds the specified HistoryInfo object to the session history.
You can use this parameter to submit a HistoryInfo object, such as the ones that are returned by the Get-History, Import-Clixml, or Import-Csv cmdlets, to **Add-History**.

Expand All @@ -96,6 +111,7 @@ Accept wildcard characters: False
```

### -Passthru

Returns a history object for each history entry.
By default, this cmdlet does not generate any output.

Expand All @@ -112,18 +128,25 @@ Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### Microsoft.PowerShell.Commands.HistoryInfo

You can pipe a HistoryInfo object to **Add-History**.

## OUTPUTS

### None or Microsoft.PowerShell.Commands.HistoryInfo

When you use the **PassThru** parameter, **Add-History** returns a HistoryInfo object.
Otherwise, this cmdlet does not generate any output.

## NOTES
* The session history is a list of the commands entered during the session along with the ID. The session history represents the order of execution, the status, and the start and end times of the command. As you enter each command, Windows PowerShell adds it to the history so that you can reuse it. For more information about the session history, see about_History.

- The session history is a list of the commands entered during the session along with the ID. The session history represents the order of execution, the status, and the start and end times of the command. As you enter each command, Windows PowerShell adds it to the history so that you can reuse it. For more information about the session history, see about_History.

To specify the commands to add to the history, use the **InputObject** parameter.
The **Add-History** command accepts only **HistoryInfo** objects, such as those returned for each command by the Get-History cmdlet.
Expand All @@ -139,7 +162,8 @@ If you intend to pass the objects back to **Add-History**, do not use the **NoTy

To edit the session history, export the session to a CSV or XML file, edit the file, import the file, and use **Add-History** to append it to the current session history.

*
-

## RELATED LINKS

[Clear-History](Clear-History.md)
Expand Down
56 changes: 38 additions & 18 deletions reference/3.0/Microsoft.PowerShell.Core/Add-PSSnapin.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
ms.date: 06/09/2017
schema: 2.0.0
locale: en-us
Expand All @@ -7,17 +7,20 @@ online version: http://go.microsoft.com/fwlink/?LinkID=113281
external help file: System.Management.Automation.dll-Help.xml
title: Add-PSSnapin
---

# Add-PSSnapin

## SYNOPSIS

Adds one or more Windows PowerShell snap-ins to the current session.

## SYNTAX

```
Add-PSSnapin [-Name] <String[]> [-PassThru] [<CommonParameters>]
```

## DESCRIPTION

The Add-PSSnapin cmdlet adds registered Windows PowerShell snap-ins to the current session.
After the snap-ins are added, you can use the cmdlets and providers that the snap-ins support in the current session.

Expand All @@ -28,55 +31,63 @@ Beginning in Windows PowerShell 3.0, the core commands that are included in Wind
The exception is **Microsoft.PowerShell.Core**, which is a snap-in (PSSnapin).
By default, only the **Microsoft.PowerShell.Core** snap-in is added to the session.
Modules are imported automatically on first use and you can use the Import-Module cmdlet to import them.

## EXAMPLES

### Example 1

```
PS C:\> add-PSSnapIn Microsoft.Exchange, Microsoft.Windows.AD
PS> add-PSSnapIn Microsoft.Exchange, Microsoft.Windows.AD
```

This command adds the Microsoft Exchange and Active Directory snap-ins to the current session.

### Example 2

```
PS C:\> get-pssnapin -registered | add-pssnapin -passthru
PS> get-pssnapin -registered | add-pssnapin -passthru
```

This command adds all of the registered Windows PowerShell snap-ins to the session.
It uses the Get-PSSnapin cmdlet with the Registered parameter to get objects representing each of the registered snap-ins.
The pipeline operator (|) passes the result to Add-PSSnapin, which adds them to the session.
The PassThru parameter returns objects that represent each of the added snap-ins.

### Example 3

```
The first command gets snap-ins that have been added to the current session, including the snap-ins that are installed with Windows PowerShell. In this example, ManagementFeatures is not returned. This indicates that it has not been added to the session.
PS C:\> get-pssnapin
PS> get-pssnapin

The second command gets snap-ins that have been registered on your system (including those that have already been added to the session). It does not include the snap-ins that are installed with Windows PowerShell.In this case, the command does not return any snap-ins. This indicates that the ManagementFeatures snapin has not been registered on the system.
PS C:\> get-pssnapin -registered
PS> get-pssnapin -registered

The third command creates an alias, "installutil", for the path to the InstallUtil tool in .NET Framework.
PS C:\> set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe
PS> set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe

The fourth command uses the InstallUtil tool to register the snap-in. The command specifies the path to ManagementCmdlets.dll, the file name or "module name" of the snap-in.
PS C:\> installutil C:\Dev\Management\ManagementCmdlets.dll
PS> installutil C:\Dev\Management\ManagementCmdlets.dll

The fifth command is the same as the second command. This time, you use it to verify that the ManagementCmdlets snap-in is registered.
PS C:\> get-pssnapin -registered
PS> get-pssnapin -registered

The sixth command uses the Add-PSSnapin cmdlet to add the ManagementFeatures snap-in to the session. It specifies the name of the snap-in, ManagementFeatures, not the file name.
PS C:\> add-pssnapin ManagementFeatures
PS> add-pssnapin ManagementFeatures

To verify that the snap-in is added to the session, the seventh command uses the Module parameter of the Get-Command cmdlet. It displays the items that were added to the session by a snap-in or module.
PS C:\> get-command -module ManagementFeatures
PS> get-command -module ManagementFeatures

You can also use the PSSnapin property of the object that the Get-Command cmdlet returns to find the snap-in or module in which a cmdlet originated. The eighth command uses dot notation to find the value of the PSSnapin property of the Set-Alias cmdlet.
PS C:\> (get-command set-alias).pssnapin
PS> (get-command set-alias).pssnapin
```

This example demonstrates the process of registering a snap-in on your system and then adding it to your session.
It uses ManagementFeatures, a fictitious snap-in implemented in a file called ManagementCmdlets.dll.

## PARAMETERS

### -Name

Specifies the name of the snap-in.
(This is the Name, not the AssemblyName or ModuleName.) Wildcards are permitted.

Expand All @@ -95,6 +106,7 @@ Accept wildcard characters: True
```

### -PassThru

Returns an object representing each added snap-in.
By default, this cmdlet does not generate any output.

Expand All @@ -111,26 +123,34 @@ Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

You cannot pipe objects to Add-PSSnapin.

## OUTPUTS

### None or System.Management.Automation.PSSnapInInfo

When you use the PassThru parameter, Add-PSSnapin returns a PSSnapInInfo object that represents the snap-in.
Otherwise, this cmdlet does not generate any output.

## NOTES
* Beginning in Windows PowerShell 3.0, the core commands that are installed with Windows PowerShell are packaged in modules. In Windows PowerShell 2.0, and in host programs that create older-style sessions in later versions of Windows PowerShell, the core commands are packaged in snap-ins ("PSSnapins"). The exception is **Microsoft.PowerShell.Core**, which is always a snap-in. Also, remote sessions, such as those started by the New-PSSession cmdlet, are older-style sessions that include core snap-ins.

- Beginning in Windows PowerShell 3.0, the core commands that are installed with Windows PowerShell are packaged in modules. In Windows PowerShell 2.0, and in host programs that create older-style sessions in later versions of Windows PowerShell, the core commands are packaged in snap-ins ("PSSnapins"). The exception is **Microsoft.PowerShell.Core**, which is always a snap-in. Also, remote sessions, such as those started by the New-PSSession cmdlet, are older-style sessions that include core snap-ins.

For information about the **CreateDefault2** method that creates newer-style sessions with core modules, see [CreateDefault2 Method](https://msdn.microsoft.com/library/system.management.automation.runspaces.initialsessionstate.createdefault2) in the MSDN library.

* For more information about snap-ins, see [about_PSSnapins](About/about_PSSnapins.md) and [How to Create a Windows PowerShell Snap-in](https://go.microsoft.com/fwlink/?LinkId=144762) in the MSDN library.
* Add-PSSnapin adds the snap-in only to the current session. To add the snap-in to all Windows PowerShell sessions, add it to your Windows PowerShell profile. For more information, see about_Profiles.
* You can add any snap-in that has been registered by using the Microsoft .NET Framework install utility. For more information, see [How to Register Cmdlets, Providers, and Host Applications](https://go.microsoft.com/fwlink/?LinkID=143619) in the MSDN library.
* To get a list of snap-ins that are registered on your computer, type get-pssnapin -registered.
* Before adding a snap-in, Add-PSSnapin checks the version of the snap-in to verify that it is compatible with the current version of Windows PowerShell. If the snap-in fails the version check, Windows PowerShell reports an error.
- For more information about snap-ins, see [about_PSSnapins](About/about_PSSnapins.md) and [How to Create a Windows PowerShell Snap-in](https://go.microsoft.com/fwlink/?LinkId=144762) in the MSDN library.
- Add-PSSnapin adds the snap-in only to the current session. To add the snap-in to all Windows PowerShell sessions, add it to your Windows PowerShell profile. For more information, see about_Profiles.
- You can add any snap-in that has been registered by using the Microsoft .NET Framework install utility. For more information, see [How to Register Cmdlets, Providers, and Host Applications](https://go.microsoft.com/fwlink/?LinkID=143619) in the MSDN library.
- To get a list of snap-ins that are registered on your computer, type get-pssnapin -registered.
- Before adding a snap-in, Add-PSSnapin checks the version of the snap-in to verify that it is compatible with the current version of Windows PowerShell. If the snap-in fails the version check, Windows PowerShell reports an error.

## RELATED LINKS

[Get-PSSnapin](Get-PSSnapin.md)
Expand Down
Loading