Welcome Forums General PowerShell Q&A Create a new local user and map a network share for the new user

Viewing 4 reply threads
  • Author
    Posts
    • #164031
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      Hey everyone,

      I am fairly new to Powershell and I am trying to mount network shares for a newly created local user.

      We have no AD, so I am logged in an local admin user.

      From there I do

      $Password = read-host AsSecurestring
      
      New-LocalUser -Name NewUser -password $Password -PasswordNeverExpires
      
      Add-LocalGroupMember -Group Users -Member NewUser
      
      
      

      Now, I want to mount a network share for the “NewUser” (without switching to the NewUser)

      Solution that worked, but probalby won’t run from a script in the feature.

      "Start-Process -filepath "powershell.exe" -Credential NewUser"

      It opens a new powershell window and I can use the

      New-PSDrive

      cmdlet to map a network share for the “New User”. But first, the new Powershell window is unresponsive as long as I haven’t closed my old Powershell window. This feels very awkward.

      Other things I tried.

      Enabled-PSremoting
      winrm quickconfig
      and set the trustedhost -value to *

      So I can run the New-PSDrive cmdlet via Invoke-Command with the credentials of the “NewUser” on my localmachine.

      Invoke-Command -ComputerName localhost -ScriptBlock{New-PSDrive -Name T -Root \\Server\Share -Persist -Scope Global} -Credential NewUser

      This will give me an Access denied error.

      Is there even an elegant way to solve my issue?

      Best regards,

      Tobias

    • #164070
      Participant
      Topics: 14
      Replies: 44
      Points: 154
      Helping Hand
      Rank: Participant

      May be a silly question, but why are you trying to connect to a share as a different user than you are logged on as? Is the share a windows share or no?

    • #164112
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      We don’t have an active directory and we often have freelancer and employees who switch PCs. We always have to create their users manually. My idea was to create a script, which runs from local admin user and basicly does the work. So they can login, have their shares mounted, and the only thing that is left is that they have to sign in into their mail accounts.

    • #164124
      Participant
      Topics: 2
      Replies: 1758
      Points: 3,646
      Helping Hand
      Rank: Community Hero

      I cannot test at the moment but I could imagine that you could use the task scheduler to help you out until you get a proper domain. 😉
      Something like this could be a start:

      $Action = New-ScheduledTaskAction -Execute 'CMD' -Argument '/C NET USE T: \\Server\Share'
      $Trigger = New-ScheduledTaskTrigger -AtLogOn -User 'NewUser' 
      $Settings = New-ScheduledTaskSettingsSet -NetworkName 'NetworkName' -RunOnlyIfNetworkAvailable
      Register-ScheduledTask -TaskPath '\YourCompany\' -TaskName 'MapShareNewUser' -Action $Action -Trigger $Trigger -Settings $Settings

      Of course you should fine tune the necessary settings.
      BTW: Sometimes it’s easier to ask a technical question in your native language – there is a German Microsoft Powershell Forum as well … just in case. 😉

    • #164142
      Participant
      Topics: 1
      Replies: 2
      Points: 19
      Rank: Member

      I cannot test at the moment but I could imagine that you could use the task scheduler to help you out until you get a proper domain.

      As soon as I can, I’m going to test it myself!

      there is a German Microsoft Powershell Forum as well

      And thank you for showing me another resource I can use in the future!

       

Viewing 4 reply threads
  • The topic ‘Create a new local user and map a network share for the new user’ is closed to new replies.