1

I need to reload my powersehll profiles from my custom script named 'profile.ps1'.

Typing the command '.$profile.All Users Hosts' from powershell everything works like a charm but if I try to use this command in my script nothing happens

Could someone kindly help me?

BorisBe
  • 11
  • 1
  • Mr Winston has given a beautiful function to achieve the same. Kindly check [HERE](https://stackoverflow.com/questions/567650/how-to-reload-user-profile-from-script-file-in-powershell/5501909#5501909) – Ranadip Dutta Dec 12 '22 at 18:49

1 Answers1

0

If you dot-source a script from within a script, any changes that it might make will be limited in scope to the script from which you’ve dot-sourced - that is, if you dot-source your profile from within the script 'bogus.ps1', the changes will go away when bogus.ps1 finishes executing. I strongly urge you to read and understand Microsoft Learn on PowerShell Scopes; asking the bingleduck about "powershell scope" will provide pointers to other sites that attempt to explain scopes in PowerShell.

Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33