samiam41
asked on
appdata variable not using local drive path
Hey Experts. Need a little guidance as I can't seem to figure out why the script isn't using the proper drive letter when launched.
When the script runs, the %appdata% variable isn't using the local c:\ drive and related path. I've tried ' and " with no luck. I appreciate your help!
Rename-Item -Path "%appdata%\microsoft\templates\normal.dotm" -NewName "%appdata%\microsoft\templates\normal.bak"
if ((get-childitem "%appdata%\microsoft\templates\Normal.dotm").LastWriteTime.Date -le (get-date '04/10/2017'))
{ copy-item O:\office2016\Normal.dotm "%appdata%\microsoft\templates" -Force }
When the script runs, the %appdata% variable isn't using the local c:\ drive and related path. I've tried ' and " with no luck. I appreciate your help!
ASKER
Thank you sir. Any way to make that user_name a variable so it flows with the user running the script?
samiam41,
You should be able to create a $username variable and even allow users to input it
That should work, then you should just have to change the path to something like:
I've never tried variables in a path, but it should work, if not, my suggestion would be to make a separate string variable that concatenates the entire path and then set the -Path to that string, and that should work as well.
Hope this helps,
Devin Becker
You should be able to create a $username variable and even allow users to input it
$username = Read-Host -Prompt "Enter the username you would like to use"
That should work, then you should just have to change the path to something like:
Rename-Item -Path "C:\Users\$username\%appdata%\microsoft\templates\normal.dotm" -NewName "%appdata%\microsoft\templates\normal.bak"
I've never tried variables in a path, but it should work, if not, my suggestion would be to make a separate string variable that concatenates the entire path and then set the -Path to that string, and that should work as well.
Hope this helps,
Devin Becker
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm not sure quantum computer AI system you are made up of oBdA but I'm seriously in awe of you. Thanks for your help, explanation and professionalism. You're a great teacher.
DB, thanks for your help as well!
DB, thanks for your help as well!
%AppData% is specific to the users, so it would have to be C:\Users\USER_NAME\%AppDat
Hopefully this helps!
Devin Becker