windows - Powershell: Variable assignment triggers module import -
this code works powershell command line generates error when run script:
$key = 'hkcu:\software\microsoft\windows\currentversion\explorer\advanced' set-itemproperty $key hidden 1
when run script, following error:
hkey_current_user\software\microsoft\windows\currentversion\explorer : module 'hkey_current_user' not loaded. more information, run 'import-module hkey_current_user'. @ c:\users\mybitch\desktop\vss-customize-desktop.ps1:19 char:6 + $key=hkey_current_user\software\microsoft\windows\currentversion\explorer + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : objectnotfound: (hkey_current_us...ersion\explorer:string) [], commandnotfoundexception + fullyqualifiederrorid : couldnotautoloadmodule
this simple assignment...why powershell try import hkey_current_user
module? why behavior different powershell command line?
the error message betrays problem. in script, apparently doing this:
$key = hkey_current_user\software\microsoft\windows\currentversion\explorer
that invalid assignment. should doing describe:
$key = 'hkcu:\software\microsoft\windows\currentversion\explorer\advanced'
Comments
Post a Comment