0

I would like to insert environment variable %username% in this powershell script:

$o = new-object -com shell.application
$o.Namespace('\\xx.local\Employee Personal Folders\Employee\%username%\Scan Folder').Self.InvokeVerb("pintohome")

How can I go about that?

Cheers in advance

1

1 Answer 1

1

PowerShell uses a different format for environment variables. For example, %USERNAME% is specified as $env:USERNAME. Try updating your code as follows:

$o = new-object -com shell.application
$o.Namespace("\\xx.local\Employee Personal Folders\Employee\$env:USERNAME\Scan Folder").Self.InvokeVerb("pintohome")

Note the double-quotes around the path string - this is required for PowerShell to automatically replace the variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Cool! I actually did some research prior to asking my question and I did try the $env:Username. However, I was using ' ' rather than " ". Causing the script to fail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.