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

  • Home
  • SEARCH
  • 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 7094151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:31:40+00:00 2026-05-28T08:31:40+00:00

I have a question i wrote a powershell script so i have name.ps1, but

  • 0

I have a question i wrote a powershell script so i have name.ps1, but i have troubles for executing it, i mean i could debut it with windows powershell (ISE), by just adding the code to it and run … but how do i execute it different?

When i open ordinary windows powershell (so NOT ISE) and i type there script.ps1 file.csv
i get this kind of error:
enter image description here

This is the code that i have, maybe im not proper initiating the script in my code i dont know:

param ([string]$Csv)

function GetHelp() {

$HelpText = @"

DESCRIPTION:

NAME: Add-STUser
Adds Users from the User Csv File

PARAMETERS: 

-Csv         The Csv file Used by the script (Required)
-help        Prints the HelpFile (Optional)


The Csv File is built up in the following way:


Firstname, Surname, Email

"@
$HelpText
}

function Get-Csv ([string]$Csv) {

    $CsvFile = Import-Csv $Csv

    $CsvFile | ForEach {

        Add-User -Firstname $_.Firstname -Surname $_.Surname -Email $_.Email
    }
}


function Add-User ([string]$Firstname, [string]$Surname, [string]$Email) {

    # Set up AD Connectionstring

        # Get A Unique Password

        [string]$Password = Generate-Password
        $username=$Firstname.substring(0,1).toLower() + $Surname.toLower()
        # Create User in AD

        $container =[ADSI] $Connection
        $User = $container.Create("User", "cn="+$username)
        $User.Put("sAMAccountName", $username)
        $User.Put("givenName", $Firstname)
        $User.Put("sn", $Surname)
        $User.Put("mail", $Email)
        $User.Put("displayName", $Firstname + " "+$Surname)
        $User.SetInfo()

        # Set Random Pwd and Enable Account

        $User.PsBase.Invoke("SetPassword", $Password)
        $User.PsBase.InvokeSet("AccountDisabled", $false)
        $User.pwdLastSet = 0
        $User.SetInfo()

        # Write Pwd to File

        $FileName = "PasswordList " + (get-date -uformat "%Y-%m-%d") + ".txt"

        "$Firstname, $Surname, $username, $email, $Password" | Add-Content $FileName

        Write-Host "Added User: $username" -ForegroundColor Green


    # Set Check Variable to False

    $Password = $Null
    #$Script:sAMAccountNameDoesntExist = $False
    #$Script:distinguishedNameDoesntExist = $False
}



if ($help) { 
    GetHelp 
} elseif ($Domain -AND $Csv) {
    Get-Csv  -Csv $Csv
} else {
    GetHelp
}

So with other words i need to execute that script with only 1 param (path to csv file)

Thanks in advance

  • 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-05-28T08:31:41+00:00Added an answer on May 28, 2026 at 8:31 am

    In Powershell, unlike cmd, current directory (.) is not in PATH.

    So to run scripts or executables in the current directory, you have to prefix with ./

    So you will have to do

    .\script.ps1 file.csv
    

    If you look carefully at the error message, at the bottom, Powershell is giving a suggestion that you have to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am quite new to Powershell but I have one niggling question. I
I have the exact same problem as the guy who wrote this question. The
I have a question about C#. I wrote a function using ASP.net, when the
Question: I have just wrote my first code using c# lambda expressions. It works,
I have a lot of PowerShell script. One main, that calls other, child ones.
I have ask similar question before : Java String Memory Leak But I was
Hey there- I'm testing jQuery Mobile and have a question. I wrote a simple
Is their anyway to test the correctness of a powershell script without executing it.
I just have a question about my cuda program that I wrote. It allows
I'm new to C++, and I have a question that should be easy, but

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.