SOLVED

Script to create a text file

%3CLINGO-SUB%20id%3D%22lingo-sub-346113%22%20slang%3D%22en-US%22%3EScript%20to%20create%20a%20text%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-346113%22%20slang%3D%22en-US%22%3E%3CP%3EAll%2C%3C%2FP%3E%3CP%3EI%20am%20looking%20to%20run%20the%20below%20one%20liner%20and%20have%20it%20create%20a%20txt%20file%20on%20the%20currently%20logged%20in%20user's%20desktop.%20When%20it%20runs%20an%20error%20is%20returned.%20Any%20suggestions%20on%20how%20to%20resolve%20the%20error%20would%20be%20appreciated.%3C%2FP%3E%3CP%3EThe%20command%20is%20below%3C%2FP%3E%3CP%3E%26nbsp%3Bget-netipaddress%20%7C%20format-table%20%26gt%3B%20%24env%3Auserprofile%20%2B%20'%5CDesktop%5Cinfo.txt'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20error%20is%20below%3C%2FP%3E%3CP%3Eout-file%20%3A%20Access%20to%20the%20path%20'C%3A%5CUsers%5Cmy_user_id'%20is%20denied.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20appreciate%20the%20response%20in%20advance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKeith%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-346113%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-352230%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20create%20a%20text%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-352230%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20using%20some%20bracketing%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eget-netipaddress%20%7C%20format-table%20%26gt%3B%20%24(%24env%3Auserprofile%20%2B%20'%5CDesktop%5Cinfo.txt')%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20should%20also%20avoid%20using%20Format-Table%20when%20writing%2Fexporting%20to%20a%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

All,

I am looking to run the below one liner and have it create a txt file on the currently logged in user's desktop. When it runs an error is returned. Any suggestions on how to resolve the error would be appreciated.

The command is below

 get-netipaddress | format-table > $env:userprofile + '\Desktop\info.txt'

 

The error is below

out-file : Access to the path 'C:\Users\my_user_id' is denied.
At line:1 char:1

 

 

I appreciate the response in advance.

 

Keith

1 Reply
best response confirmed by Keith732 (New Contributor)
Solution

Try using some bracketing:

 

get-netipaddress | format-table > $($env:userprofile + '\Desktop\info.txt')

 

You should also avoid using Format-Table when writing/exporting to a file.