< Back
Invoke-PSFCommand
Post
NAME Invoke-PSFCommand
SYNOPSIS
An Invoke-Command wrapper with integrated session management.
SYNTAX
Invoke-PSFCommand [[-ComputerName] <ComputerParameter[]>] [-ScriptBlock] <ScriptBlock> [[-ArgumentList]
<Object[]>] [[-Credential] <PSCredential>] [-HideComputerName] [[-ThrottleLimit] <Int32>] [<CommonParameters>]
DESCRIPTION
This wrapper command around Invoke-Command allows conveniently calling remote calls.
- It uses the PSFComputer parameter class, and is thus a lot more flexible in accepted input
- It automatically reuses sessions specified for input
- It automatically establishes new sessions, tracks usage and retires sessions that have timed out.
Using this command, it is no longer necessary to first establish a connection and then manually handle the session
object.
Just point the command at the computer and it will remember.
It also reuses sessions across multiple commands that call it.
Note:
Special connection conditions (like a custom application name, alternative authentication schemes, etc.) are not
supported and require using New-PSSession to establish the connection.
Once that session has been established, the session object can be used with this command and will be used for
command invocation.
PARAMETERS
-ComputerName <ComputerParameter[]>
The computer(s) to invoke the command on.
Accepts all kinds of things that legally point at a computer, including DNS names, ADComputer objects, IP
Addresses, SQL Server connection strings, CimSessions or PowerShell Sessions.
It will reuse PSSession objects if specified (and not include them in its session management).
Required? false
Position? 1
Default value $env:COMPUTERNAME
Accept pipeline input? false
Accept wildcard characters? false
-ScriptBlock <ScriptBlock>
The code to execute.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ArgumentList <Object[]>
The arguments to pass into the scriptblock.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Credential <PSCredential>
Credentials to use when establishing connections.
Note: These will be ignored if there already exists an established connection.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-HideComputerName [<SwitchParameter>]
Indicates that this cmdlet omits the computer name of each object from the output display. By default, the
name of the computer that generated the object appears in the display.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-ThrottleLimit <Int32>
Specifies the maximum number of concurrent connections that can be established to run this command. If you
omit this parameter or enter a value of 0, the default value, 32, is used.
Required? false
Position? 5
Default value 32
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Invoke-PSFCommand -ScriptBlock $ScriptBlock
Runs the $scriptblock against the local computer.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-PSFCommand -ScriptBlock $ScriptBlock (Get-ADComputer -Filter "name -like 'srv-db*'")
Runs the $scriptblock against all computers in AD with a name that starts with "srv-db".
RELATED LINKS
SYNOPSIS
An Invoke-Command wrapper with integrated session management.
SYNTAX
Invoke-PSFCommand [[-ComputerName] <ComputerParameter[]>] [-ScriptBlock] <ScriptBlock> [[-ArgumentList]
<Object[]>] [[-Credential] <PSCredential>] [-HideComputerName] [[-ThrottleLimit] <Int32>] [<CommonParameters>]
DESCRIPTION
This wrapper command around Invoke-Command allows conveniently calling remote calls.
- It uses the PSFComputer parameter class, and is thus a lot more flexible in accepted input
- It automatically reuses sessions specified for input
- It automatically establishes new sessions, tracks usage and retires sessions that have timed out.
Using this command, it is no longer necessary to first establish a connection and then manually handle the session
object.
Just point the command at the computer and it will remember.
It also reuses sessions across multiple commands that call it.
Note:
Special connection conditions (like a custom application name, alternative authentication schemes, etc.) are not
supported and require using New-PSSession to establish the connection.
Once that session has been established, the session object can be used with this command and will be used for
command invocation.
PARAMETERS
-ComputerName <ComputerParameter[]>
The computer(s) to invoke the command on.
Accepts all kinds of things that legally point at a computer, including DNS names, ADComputer objects, IP
Addresses, SQL Server connection strings, CimSessions or PowerShell Sessions.
It will reuse PSSession objects if specified (and not include them in its session management).
Required? false
Position? 1
Default value $env:COMPUTERNAME
Accept pipeline input? false
Accept wildcard characters? false
-ScriptBlock <ScriptBlock>
The code to execute.
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ArgumentList <Object[]>
The arguments to pass into the scriptblock.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Credential <PSCredential>
Credentials to use when establishing connections.
Note: These will be ignored if there already exists an established connection.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-HideComputerName [<SwitchParameter>]
Indicates that this cmdlet omits the computer name of each object from the output display. By default, the
name of the computer that generated the object appears in the display.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-ThrottleLimit <Int32>
Specifies the maximum number of concurrent connections that can be established to run this command. If you
omit this parameter or enter a value of 0, the default value, 32, is used.
Required? false
Position? 5
Default value 32
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Invoke-PSFCommand -ScriptBlock $ScriptBlock
Runs the $scriptblock against the local computer.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-PSFCommand -ScriptBlock $ScriptBlock (Get-ADComputer -Filter "name -like 'srv-db*'")
Runs the $scriptblock against all computers in AD with a name that starts with "srv-db".
RELATED LINKS