# Understanding PowerShell Variable in Script

**URL:** <https://forums.powershell.org/t/understanding-powershell-variable-in-script/17188>\
**Category:** PowerShell Help\
**Created:** [July 29, 2021, 4:04pm UTC](https://forums.powershell.org/t/understanding-powershell-variable-in-script/17188 "2021-07-29T16:04:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orlandot](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@orlandot](https://forums.powershell.org/u/orlandot)\
**Post date:** [July 29, 2021, 4:04pm UTC](https://forums.powershell.org/t/understanding-powershell-variable-in-script/17188/1 "2021-07-29T16:04:52Z")

</div>

Hi All,

I have a Powershell script in the form of a function with the following line in it

$ClientInstaller = "$($Path)\update.exe

I understand this should be going to the executable location and creating a path variable for $clientinstaller.

What I need help with is understanding what "$($Path) is actually doing? My assumption is telling PowerShell to scan the drive for Update.exe and use that location as the Path for the variable but I am not sure.

Can someone help me understand what that section of the script is actually doing?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 29, 2021, 8:31pm UTC](https://forums.powershell.org/t/understanding-powershell-variable-in-script/17188/2 "2021-07-29T20:31:22Z")

</div>

I’d assume this code is actually incomplete and it should actually look like this:

```auto
$ClientInstaller = "$($Path)\update.exe"

```

> [@orlandot](#):
>
> I understand this should be going to the executable location and creating a path variable for $clientinstaller.

Hmmm … no. There’s nothing going anywhere. It actually creates a string variable by concatenating the content of the variable `$Path` and the string “`\update.exe`”.

> [@orlandot](#):
>
> What I need help with is understanding what "$($Path) is actually doing? My assumption is telling PowerShell to scan the drive for Update.exe and use that location as the Path for the variable but I am not sure.

No. As you obviously already know is `$Path` a variable. And there’s probably a folder path in it. To wrap it in a dollar sign and parenthesis is called subexpression and should actually be unnecessary in this case. It would execute code or an expression inside before continuing the code execution outside. The following should be enough in such cases:

```auto
$ClientInstaller = "$Path\update.exe"

```

PowerShell will expand variables inside double quotes. If you had “`C:\Users\orlandot\Dowloads`” saved in the variable $Path for example the result of the variable assignment

```auto
$ClientInstaller = "$Path\update.exe"

```

or

```auto
$ClientInstaller = "$($Path)\update.exe"

```

would be in both cases

```auto
C:\Users\orlandot\Dowloads\update.exe

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:22pm UTC](https://forums.powershell.org/t/understanding-powershell-variable-in-script/17188/3 "2024-05-16T20:22:57Z")

</div>


