Paste username into Powershell file path

We are trying to tidy up our home user directories and speed up work in Office 2007 by moving all their templates to a new directory on our user drive (U :). During my initial tests, I can get the below script to work fine, although it has an obvious problem only for working with my username. Is there a way to get him to take the current user login? Before this will be processed by% username% and from a short-term scan of the Internet, obviously:

$[Environment]::UserName 

Must work. However, it seems I am getting errors. Is there a better way to achieve the current login in the username in the file path?

if (!(Test-Path -path '\\SERVER\PATH\TO FILES\$[Environment]::UserName\Normal\'))
{
New-Item '\\SERVER\PATH\TO FILES\$[Environment]::UserName\Normal\' -type directory
##Move-Item \\SERVER\PATH\TO FILES\$env:username\Normal.dot \\\SERVER\PATH\TO FILES\$env:username\Normal\
## Move-Item \\SERVER\PATH\TO FILES\$env:username\*.dotm \\SERVER\PATH\TO FILES\%username%\Normal\
}
else
{
"No work to do"
}
+3
1

. , / , , , . .

"\\SERVER\PATH\TO FILES\$([Environment]::UserName)\Normal\"
+5

Source: https://habr.com/ru/post/1777488/


All Articles