Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:57:45+00:00 2026-06-06T18:57:45+00:00

I am attempting to add a username to file path so I can create

  • 0

I am attempting to add a username to file path so I can create a directory that contains their username.

This is how I want my User Folder to Look:

D:\Test Space\ArtP$

When I do this in a Shell:

PS > $samAccountName = "ArtP"
PS > $user_folder = "D:\Test Space\$samAccountName$"
PS > $user_folder
D:\Test Space\ArtP$

It works as expected. I then try this in a script that is supposed to do this on a remote server:

 $samAccountName = "ArtP"
 $user_folder = "D:\Test Space\$samAccountName$"
 invoke-command -computername remote_server -scriptblock {
     new-item -path $user_folder -type directory -Force
 }

I get the following error:

Cannot bind argument to parameter 'Path' because it is null.
    + CategoryInfo          : InvalidData: (:) [New-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewItemComm
   and

It is saying my path is null and I believe there is some discrepancy about how the shell interprets quotes and how the script is. How do I get my user name in the file path above properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:57:46+00:00Added an answer on June 6, 2026 at 6:57 pm

    Refer to the section about Passing Local Values in How to pass arguments for remote commands

    $samAccountName = "ArtP"
    $user_folderLocalValue = "D:\Test Space\$samAccountName"
    

    With Param:

    invoke-command -computername remote_server -scriptblock {
    param($user_folder)
    new-item -path $user_folder -type directory -Force
    } -Args $user_folderLocalValue
    

    or with $args

    invoke-command -computername remote_server -scriptblock {
    new-item -path $args[0] -type directory -Force
    } -Args $user_folderLocalValue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to add a function that will create a csv for download
I'm attempting to add a custom dialog box to my current GUI that can
I am attempting to add some functions to backbone so that I can communicate
I'm attempting to add a function to my site where users can set their
I'm attempting to add a legend to a graph, and I want to append
I'm attempting to add a bookmarklet to my wop website. The issue is that
I'm attempting to add a cmake build system to an old fortran code that
I am attempting to add a simple toolstrip however I can't get it to
I'm attempting to Create a Job and Add a Batch using the Salesforce Bulk
Basically I'm attempting to add rows to a table, I need to do this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.