Avatar of jskfan
jskfan
Flag for Cyprus asked on

Explain Powershell Command

Explain Powershell Command

I have this Powershell code, I would like to have an Expert explain it. some of it is clear , some of it not sure what it does.
for instance:

 %
$env:temp

Thank you.



import-csv C:\CSVFILE.csv | % { Invoke-Command -ComputerName $($_.COMPUTERNAME) -ScriptBlock { copy "\\server\share\regFile.reg" $env:temp ;  reg.exe import $env:temp\regFile.reg } 

Open in new window

Powershell

Avatar of undefined
Last Comment
David Johnson, CD

8/22/2022 - Mon
David Johnson, CD

% Is an alias to for-eachobject
$env:temp  reads the environmental variables for the name temp and uses the value
import-csv C:\CSVFILE.csv | ForEach-Object
     { 
       Invoke-Command -ComputerName $($_.COMPUTERNAME) -ScriptBlock 
          { 
          Copy-Item "\\server\share\regFile.reg" $env:temp 
          reg.exe import $env:temp\regFile.reg 
          }
      }
       

Open in new window

Tom Cieslik

David has right.
You can also study this article, maybe this will give you some more explanation
https://blogs.msdn.microsoft.com/timid/2009/10/11/powershell-for-n00bs-envtemp-vs-temp/
ASKER CERTIFIED SOLUTION
Jose Gabriel Ortega Castro

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jskfan

ASKER
Sorry Guys for the Delay...was busy...

Can someone elaborate on this part of the code below ?

Copy "\\server\share\regFile.reg" $env:temp ;    //copy the regfIle in the shared \\server\share to the "temporal value" on C:\windows\temp
reg.exe import $env:temp\regFile.reg     //this will run the import to add the registry file (now in C:\windows\temp\regFile.reg) 
into that particular computer.

Open in new window



If the copy was to different folder  instead of windows temp folder , then should we create an environment variable for that folder ?

I also see Reg.exe in the code , what does it do ?  I am familiar with Regedit.exe, but not reg.exe

Thank you
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
jskfan

ASKER
Thanks
I will come back to this topic sometime in the future
David Johnson, CD

reg /?

REG Operation [Parameter List]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT  | FLAGS ]

Return Code: (Except for REG COMPARE)

  0 - Successful
  1 - Failed

For help on a specific operation type:

  REG Operation /?

Examples:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?
  REG FLAGS /?

Open in new window

 REG IMPORT AppBkUp.reg
    Imports registry entries from the file AppBkUp.reg

If the copy was to different folder  instead of windows temp folder , then should we create an environment variable for that folder ?
no just provide a full path to the .reg file