Fix $Profile default location Issue

I try to get $profile default location and try to create folder to build own module as below.

$moduleFolder = $env:PSModulePath.Split(';')[0]
mkdir "$modulesFolder\SqlAutomation"

But folder ‘SqlAutomation’ getting created in C:\ drive rather $Profile default folder. I did verify path using Test-Path for all of 4 $profiles and all come with ‘True’.

I try to add location in .ps1 file as

set-location C:\Users\sonny\Documents\WindowsPowerShell\Modules

Further Info…

C:\Users\sonny\Documents\WindowsPowerShell\Modules> $env:PSModulePath.Split(';')
C:\Users\swarn\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules
C:\Users\sonny\Documents\WindowsPowerShell\Modules> $moduleFolder
C:\Users\swarn\Documents\WindowsPowerShell\Modules

I have searched net for solution but no luck… looking for help

Thanks in advance

sonny, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code or error messages or sample data or console output format it as code, please.
In the “Text” view you can use the code tags “PRE”, in the “Visual” view you can use the format template “Preformatted”. You can go back edit your post and fix the formatting - you don’t have to create a new one.
Thanks in advance.

You have a typo in your mkdir command … $modulesFolder instead of $moduleFolder.

Olaf, Thanks for help good spotting… I tried to fix the entry as per your nstructions… hope should be fine otherwise do let me know ad I will fix it.

I am newbie in PowerShell domain… been watching videos and read articles on Microsoft and other experts include dbatools ones.

My background on Windows platform so will take bit of time to get use of writing code on command line platform to avoid such syntax mistake…

I am try to write install SSMS on SQL server… appreciate referencs/guideness if you can help with.

Cheers

That’s just fine. Thanks.

You could make your life easier by using VSCode as your script editor. That would alert you about this kind of errors/mistakes.