Link to home
Start Free TrialLog in
Avatar of jskfan
jskfanFlag 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

Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

% 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

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
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
Avatar of jskfan

ASKER

Thanks
I will come back to this topic sometime in the future
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