Scope Variable usage

Welcome Forums General PowerShell Q&A Scope Variable usage

Viewing 2 reply threads
  • Author
    Posts
    • #271996
      Participant
      Topics: 138
      Replies: 287
      Points: 449
      Rank: Contributor

      I have this script that places a variable to adjust for PS 2.0 but as my DCs are all higher, wanted to try it with a Remote Variable ($Using:<VariableName>)

      I read this: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_variables?view=powershell-7.1

      ..but not seeing how to adapt for my particular script.

      Current script:

      How would I adapt this:

      ..into my code, pulling the “$Patches = ” line out of the Invoke-Command?

      Would it be:
      $Patches = “‘KB4586793’, ‘KB4580422’, ‘KB4587735′”

      then, under Invoke-Command:

      Get-HotFix -Id $Using:Patches

      • This topic was modified 2 weeks, 1 day ago by Jeff Taylor.
      • This topic was modified 2 weeks, 1 day ago by Jeff Taylor.
    • #271999
      Participant
      Topics: 16
      Replies: 1855
      Points: 3,568
      Helping Hand
      Rank: Community Hero

      Yes, if it is not contained in the scriptblock, then you need to use the Using keyword to reference the variable outside of the scriptblock.

    • #272008
      Participant
      Topics: 138
      Replies: 287
      Points: 449
      Rank: Contributor

      Very cool….running….thank you for confirming usage here.

      Hasn’t finished but will let it go for awhile against those 3 Patches.

      • This reply was modified 2 weeks, 1 day ago by Jeff Taylor.
Viewing 2 reply threads
  • You must be logged in to reply to this topic.