Creating a folder with the name of the user that is currently logged in

2.3k Views Asked by At

I am currently working on a program that will grab info from a lot of PC's on the domain and upload the file via FTP, I need the name of each text document to match the current user logged in. Is this possible and how would I go around doing this?

1

There are 1 best solutions below

3
On BEST ANSWER

Jeeva's $env:username method works just fine:

New-Item "C:\$env:username.txt" -type File

But if you need the domain that the user belongs to, use the $env:userdomain variable, like-so:

New-Item "C:\$env:userdomain-$env:username.txt" -type File