Fairly new to powershell.
I am trying to create two subfolder based on a user input variable. These subfolders are Bookmarks and Organisers
I can create the main folder based on this variable, however all subfolders I try and create go to the root F:\ drive directory instead of being nested.
See code below
Import-Module NTFSSecurity
Import-Module ActiveDirectory
$userloginname = Read-host -Prompt "Enter the users name"
$s2 = New-PSSession -ComputerName SERVERNAME
Invoke-Command -ScriptBlock {param($userloginname)New-Item -Name $userloginname -ItemType directory -Path "f:\"} -ArgumentList $userloginname -Session $s2 **#this creates fine under F drive**
Invoke-Command -ScriptBlock {Set-Location f:\$userloginname\} -Session $s2
Invoke-Command -ScriptBlock {param($userloginname)New-Item f:\$userloginname\Organisers -ItemType directory -force} -Session $s2 ##Doesnt nest under f:/$userloginname
Invoke-Command -ScriptBlock {param($userloginname)New-Item f:\$userloginname\Bookmarks -ItemType directory -force} -Session $s2 ##Doesnt nest under f:/$userloginname
I thought this would be fairly simple but no matter what combination or ordering it never nests under f:$userloginname
Is there something I am doing wrong?
-ArgumentList. For the others you don't? Either pass in$userloginnamethe same way using-ArgumentListor change to$using:userloginnamelearn.microsoft.com/en-us/powershell/module/…