Using $env variables remotely - issues

Welcome Forums General PowerShell Q&A Using $env variables remotely - issues

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
7 months, 3 weeks ago.

  • Author
    Posts
  • #96668

    Participant
    Points: 0
    Rank: Member

    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

  • #96773

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    Thanks for the follow-up!!

The topic ‘Using $env variables remotely - issues’ is closed to new replies.