SOLVED

How to make a file in localappdata location using powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-1804805%22%20slang%3D%22en-US%22%3EHow%20to%20make%20a%20file%20in%20localappdata%20location%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1804805%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20create%20a%20file%20in%20the%20localappdata%20location%20in%20powershell.%20i%20have%20tried%20using%20%3CEM%3E%24env%3Alocalappdata%3C%2FEM%3E%20but%20it%20just%20shows%20the%20localappdata%20location%20just%20like%20%3CEM%3Ewrite-host%20C%3A%5CUsers%5C%25username%25%5CAppData%5CLocal%3C%2FEM%3E.%20I%20want%20to%20go%20to%20that%20location%20but%20it%20cant%20be%20done%20like%20in%20cmd%20i%20can%20just%20do%20cd%20%25localappdata%25.%20My%20main%20goal%20is%20to%20create%20a%20file%20there%20and%20delete%20it%20at%20certain%20condition.%20How%20do%20I%20change%20directory%20to%20%25localappdata%25%20location%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1804805%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1805293%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20make%20a%20file%20in%20localappdata%20location%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1805293%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F717814%22%20target%3D%22_blank%22%3E%40Waqaarahsab%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eif%20you%20want%20to%20change%20the%20current%20directory%20to%20go%20to%20AppData%2C%20try%26nbsp%3Bset-location%20%24env%3ALOCALAPPDATA%3C%2FP%3E%3CP%3Eif%20you%20want%20to%20write%20content%20to%20the%20folder%3C%2FP%3E%3CP%3Edid%20you%20try%20something%20like%20this%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ENew-Item%20-Path%20%22%24(%24env%3ALOCALAPPDATA)%5CNewContent.txt%22%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I am trying to create a file in the localappdata location in powershell. i have tried using $env:localappdata but it just shows the localappdata location just like write-host C:\Users\%username%\AppData\Local. I want to go to that location but it cant be done like in cmd i can just do cd %localappdata%. My main goal is to create a file there and delete it at certain condition. How do I change directory to %localappdata% location? 

2 Replies
Best Response confirmed by Waqaarahsab (Occasional Contributor)
Solution

@Waqaarahsab 

if you want to change the current directory to go to AppData, try set-location $env:LOCALAPPDATA

if you want to write content to the folder

did you try something like this

New-Item -Path "$($env:LOCALAPPDATA)\NewContent.txt"

@farismalaeb Thank you, I never knew it was that simple :grinning_face_with_sweat: