# Using $env variables remotely - issues

**URL:** <https://forums.powershell.org/t/using-env-variables-remotely-issues/10351>\
**Category:** PowerShell Help\
**Created:** [March 21, 2018, 12:42pm UTC](https://forums.powershell.org/t/using-env-variables-remotely-issues/10351 "2018-03-21T12:42:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wei-yen-tan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/wei-yen-tan/32/91_2.png) [@wei-yen-tan](https://forums.powershell.org/u/wei-yen-tan)\
**Post date:** [March 21, 2018, 12:42pm UTC](https://forums.powershell.org/t/using-env-variables-remotely-issues/10351/1 "2018-03-21T12:42:01Z")

</div>

So I was completing a function that I want to create a xml file on the remote machines $env:tmp directory. It creates it using a scheduled task using the PSWindowsupdate module using Invoke-WUinstall.

So I create it like this:

```
{ $wuinstaller = New-Object -ComObject "Microsoft.Update.Installer"; $wuinstaller | export-clixml "$env:tmp\wuinstaller.xml" -Force }
```

When I import it:

Invoke-Command -ComputerName $computer { Import-Clixml $env:tmp\wuinstaller.xml -Force }

I get errors similar to this :

```
Could not find file 'C:\Users\weiyentan\AppData\Local\Temp\wuinstaller.xml'.
    + CategoryInfo : OpenError: (:) [Import-Clixml], FileNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportClixmlCommand
    + PSComputerName : server01
```

Yet, when I do the explicitly define the directory such as

$wuinstaller = New-Object -ComObject “Microsoft.Update.Installer”; $wuinstaller | export-clixml C:\windows\Temp\wureboot.xml -Force

It works…a bit confused …any help appreciated.

EDIT:

While I was testing out my hypothesis and drafting the post I realized the problem. So I thought that I will write that down for posterity .

Basically when the invoke-wuinstall function runs, it creates a scheduled task in the destination machine. BUT it is running it in the context of the SYSTEM user account, as it is Windows Update commands that it is running.

Which means when I use Invoke-command under my context it doesn’t find it.

Hope that it is useful for someone that is having issues with wondering why things arent working properly in a similar situaton

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 22, 2018, 10:23am UTC](https://forums.powershell.org/t/using-env-variables-remotely-issues/10351/2 "2018-03-22T10:23:12Z")

</div>

Thanks for the follow-up!!

---

<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:36pm UTC](https://forums.powershell.org/t/using-env-variables-remotely-issues/10351/3 "2024-05-16T20:36:10Z")

</div>


