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
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ Invoke-Command -Session $s -ScriptBlock {Get-WinEvent -LogName $ps}
You can use local variables in remote commands, but the variable must be
defined in the local session.

Beginning in PowerShell 3.0, you can use the `Using` scope modifier to identify
a local variable in a remote command.
Beginning in PowerShell 3.0, you can use the `Using:` scope modifier to
identify a local variable in a remote command.

The syntax of `Using` is as follows:
The syntax of `Using:` is as follows:

```
$Using:<VariableName>
```

In the following example, the `$ps` variable is created in the local session,
but is used in the session in which the command runs. The `Using` scope
but is used in the session in which the command runs. The `Using:` scope
modifier identifies `$ps` as a local variable.

```powershell
Expand All @@ -69,17 +69,17 @@ Invoke-Command -ComputerName S1 -ScriptBlock {
}
```

The `Using` scope modifier can be used in a **PSSession**.
The `Using:` scope modifier can be used in a **PSSession**.

```powershell
$s = New-PSSession -ComputerName S1
$ps = "*PowerShell*"
Invoke-Command -Session $s -ScriptBlock {Get-WinEvent -LogName $Using:ps}
```

A variable reference such as `$using:var` expands to the value of variable
A variable reference such as `$Using:var` expands to the value of variable
`$var` from the caller's context. You do not get access to the caller's
variable object. The `Using` scope modifier cannot be used to modify a local
variable object. The `Using:` scope modifier cannot be used to modify a local
variable within the **PSSession**. For example, the following code does not
work:

Expand All @@ -89,7 +89,7 @@ $ps = "*PowerShell*"
Invoke-Command -Session $s -ScriptBlock {$Using:ps = 'Cannot assign new value'}
```

For more information about `Using`, see [about_Scopes](./about_Scopes.md)
For more information about `Using:`, see [about_Scopes](./about_Scopes.md)

### Using splatting

Expand All @@ -98,20 +98,20 @@ command. For more information, see [about_Splatting](about_Splatting.md).

In this example, the splatting variable, `$Splat` is a hash table that is set
up on the local computer. The `Invoke-Command` connects to a remote computer
session. The **ScriptBlock** uses the `Using` scope modifier with the At (`@`)
session. The **ScriptBlock** uses the `Using:` scope modifier with the At (`@`)
symbol to represent the splatted variable.

```powershell
$Splat = @{ Name = "Win*"; Include = "WinRM" }
Invoke-Command -Session $s -ScriptBlock { Get-Service @Using:Splat }
```

### Other situations where the 'Using' scope modifier is needed
### Other situations where the `Using:` scope modifier is needed

For any script or command that executes out of session, you need the `Using`
For any script or command that executes out of session, you need the `Using:`
scope modifier to embed variable values from the calling session scope, so that
out of session code can access them. The `Using` scope modifier is supported in
the following contexts:
out of session code can access them. The `Using:` scope modifier is supported
in the following contexts:

- Remotely executed commands, started with `Invoke-Command` using the
**ComputerName** or **Session** parameter (remote session)
Expand All @@ -138,7 +138,7 @@ It has the type properties and methods. For simple types, such as
imperfect. For example, rehydrated certificate objects do not include the
private key.

Instances of all other types are **PSObject** instances. The **PSTypeNames**
Instances of all other types are **PSObject** instances. The **pstypenames**
property contains the original type name prefixed with **Deserialized**, for
example, **Deserialized.System.Data.DataTable**

Expand All @@ -158,14 +158,14 @@ cmdlet to specify the local variable as the parameter value.
the local variable as the parameter value.

For example, the following commands define the `$ps` variable in the local
session and then use it in a remote command. The command uses `$log` as the
session and then use it in a remote command. The command uses `$Log` as the
parameter name and the local variable, `$ps`, as its value.

```powershell
$ps = "*PowerShell*"
Invoke-Command -ComputerName S1 -ScriptBlock {
param($log)
Get-WinEvent -LogName $log
param($Log)
Get-WinEvent -LogName $Log
} -ArgumentList $ps
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ specified in both statements aren't met, the script doesn't run. Each
```powershell
#Requires -Modules PSWorkflow
#Requires -Version 3
Param
param
(
[parameter(Mandatory=$true)]
[String[]]
[Parameter(Mandatory=$true)]
[string[]]
$Path
)
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ their own help articles. To view them, type `Get-Help about_` and add the
keyword. For example, to get information about the `foreach` statement, type:

```powershell
Get-Help about_ForEach
Get-Help about_Foreach
```

For information about the `filter` statement or the `return` statement syntax,
Expand Down
30 changes: 15 additions & 15 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Return.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Users who are familiar with languages like C or C\# might want to use the
`return` keyword to make the logic of leaving a scope explicit.

In PowerShell, the results of each statement are returned as output, even
without a statement that contains the Return keyword. Languages like C or C\#
without a statement that contains the `return` keyword. Languages like C or C\#
return only the value or values that are specified by the `return` keyword.

> [!NOTE]
Expand Down Expand Up @@ -58,10 +58,10 @@ because the return statement exits before that statement can execute.
```powershell
function MultiplyEven
{
param($number)
param($Number)

if ($number % 2) { return "$number is not even" }
$number * 2
if ($Number % 2) { return "$Number is not even" }
$Number * 2
}

1..10 | ForEach-Object {MultiplyEven -Number $_}
Expand Down Expand Up @@ -99,15 +99,15 @@ The following example includes a statement intended to let the user know that
the function is performing a calculation:

```powershell
function calculation {
param ($value)
function Calculation {
param ($Value)

"Please wait. Working on calculation..."
$value += 73
return $value
$Value += 73
return $Value
}

$a = calculation 14
$a = Calculation 14
```

The "Please wait. Working on calculation..." string is not displayed. Instead,
Expand All @@ -128,20 +128,20 @@ the above example using the `Write-Information` cmdlet with a
**InformationAction** set to `Continue`.

```powershell
function calculation {
param ($value)
function Calculation {
param ($Value)

Write-Information "Please wait. Working on calculation..." -InformationAction Continue
$value += 73
return $value
$Value += 73
return $Value
}
```

Now the information message to display in the host and not assigned to the
variable.

```powershell
PS> $a = calculation 14
PS> $a = Calculation 14
Please wait. Working on calculation...
PS> $a
87
Expand All @@ -152,7 +152,7 @@ PS> $a
When you return a collection from your script block or function, PowerShell
automatically unrolls the members and passes them one at a time through the
pipeline. This is due to PowerShell's one-at-a-time processing. For more
information, see [about_pipelines](about_pipelines.md).
information, see [about_Pipelines](about_pipelines.md).

This concept is illustrated by the following sample function that returns an
array of numbers. The output from the function is piped to the `Measure-Object`
Expand Down
Loading