# Don't have access to object after script ends

**URL:** <https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425>\
**Category:** PowerShell Help\
**Created:** [August 27, 2021, 8:02am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425 "2021-08-27T08:02:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kolaborek](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@kolaborek](https://forums.powershell.org/u/kolaborek)\
**Post date:** [August 27, 2021, 8:02am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/1 "2021-08-27T08:02:00Z")

</div>

Hello,  
I write some script in Visual Studio Code. After I run it and after it ends its job I have access to object generated by this script. I need access to it for further, manual, analyse.

But when I run this script from Windows Terminal with PS 7.1 or from Windows Powershell 5.1 I don’t have access to this object… it is empty.  
I tried with setting scope for this object to global ($global:object\_name), but this don’t help.

What should I do to have access to object generated by script, after it ends its work?

Best Regards

---

<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:** [August 27, 2021, 9:12am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/2 "2021-08-27T09:12:17Z")

</div>

> [@kolaborek](#):
>
> But when I run this script from Windows Terminal with PS 7.1 or from Windows Powershell 5.1 I don’t have access to this object… it is empty.

How do you run this script? Did you try to “_dot source_” it?

---

<div class="post-metadata">

**Author:** ![kolaborek](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@kolaborek](https://forums.powershell.org/u/kolaborek)\
**Post date:** [August 27, 2021, 9:26am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/3 "2021-08-27T09:26:05Z")

</div>

From VSC I run it by F5 and from Windows Terminal or PowerShell 5.1 I type .\script.ps1 and hit enter.

---

<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:** [August 27, 2021, 9:29am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/4 "2021-08-27T09:29:13Z")

</div>

> [@kolaborek](#):
>
> from Windows Terminal or PowerShell 5.1 I type .\script.ps1 and hit enter.

Try to “_dot source_” it! Instead of

```auto
.\script.ps1

```

You do

```auto
. .\script.ps1

```

!! Please notice the dot and the space in front of the script path !!

---

<div class="post-metadata">

**Author:** ![kolaborek](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@kolaborek](https://forums.powershell.org/u/kolaborek)\
**Post date:** [August 27, 2021, 9:34am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/5 "2021-08-27T09:34:32Z")

</div>

It works !🙂  
But, to be honest, this is new information for me.  
Thank you 🙂

---

<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:** [August 27, 2021, 9:44am UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/6 "2021-08-27T09:44:56Z")

</div>

You may read more about that topic …

> **[about Scopes - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.2&viewFallbackFrom=powershell-7.1)**
>
> Explains the concept of scope in PowerShell and shows how to set and change the scope of elements.

---

<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:21pm UTC](https://forums.powershell.org/t/dont-have-access-to-object-after-script-ends/17425/7 "2024-05-16T20:21:43Z")

</div>

Closed on May 16, 2024, 8:21pm UTC


