PowerShell summer tips 04
PowerShell Summer Tips #4
When working with PowerShell my recommendation is allways to start PowerShell
with Run As Administrator.
Try this without doing it:
# Create a folder in c:\Program Files
New-Item "C:\Program Files\My Folder"
# Create a folder in c:\windows
New-Item "C:\Windows\My Folder"
# List all folders in c:\windows stop on error
Get-ChildItem "C:\Windows" -Recurse -ErrorAction Stop
# Create a registry key
New-Item -Path "HKLM:\Software" -Name "My Software"
You can be administrator on the computer It does not matter.
It will work as It does in Windows doing the same stuff in the GUI.
And this is only some of the stuff that you can’t do when not running PowerShell As Administrator.
Some things will not show an error.
Just show you the wrong output.
One example is when working with Active Directory.
Some properties will not show If you are in an PowerShell session without Run As Administrator.
Even if you are the domain admin.
When scripting you can use this to be sure that the code is run in an elevated session.
# Require PowerShell to be Run As Administrator
Or else your script won’t run!