Use PowerShell Variables

Posted on 2012-08-26
Last Modified: 2012-08-26
Hello everyone.  This is a pretty basic question, but I am new to Powershell for the most part and have been struggling..  I am trying to utilize some of the environment variables to draft a automated task.  For example I would like to create a "testing" folder within all user profiles.

So when I run the Get-ChildItem Env: command, I see that "USERPROFILE" is listed as an evironment variable.  Great!  Just like a Command Prompt/DOS script right?  Wrong.  when I run this command:

PS c:\Users\UserName> md %USERPROFILE%\testing

It creates a folder like this:

Well that isn't what I wanted....  Hmm.  What am I missing here in the PowerShell world?
Question by:4roi
    LVL 13

    Accepted Solution

    Try this:

    $Path =  "$env:Userprofile\Testing" 
    New-Item $Path -type directory

    Author Comment

    Yep, That takes care of the immediate need.  It should also put me in the right direction for other commands.  Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
    How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
    This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
    The viewer will learn how to download, install and use CrashPlan from on Windows 7. Open your browser and go to Click get started, it’s free then Click the Download CrashPlan button: Click save in Internet Explorer, the…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now