locked
Homeshare in Powershell with AD Attributes RRS feed

  • Question

  • Hello

    I wrote a script witch adds the homeshare.

    $User = $env:USERNAME
    Get-ADUser $User -Properties Department, Company
    $UserP = "\\Server\$($User.Company)\$($User.Department)_Userhomes\$User"
    New-PSDrive -Name "P" -PSProvider FileSystem -Root "$UserP"

    If i check $UserP i get:

    \\Server\\_Userhomes\Administrator

    and i need the AD Attributes...

    Thanks for your help

    Tuesday, February 19, 2019 2:47 PM

Answers

  • I got it...

    $User = $env:USERNAME
    $Userdep = Get-ADUser $User -Properties Department | Select-Object -ExpandProperty Department
    $Usercom = Get-ADUser $User -Properties Company | Select-Object -ExpandProperty Company
    $UserP = "\\Server\$($Usercom)\$($Userdep)_Userhomes\$User"

    • Marked as answer by AndreH Tuesday, February 19, 2019 3:40 PM
    Tuesday, February 19, 2019 3:08 PM

All replies

  • I got it...

    $User = $env:USERNAME
    $Userdep = Get-ADUser $User -Properties Department | Select-Object -ExpandProperty Department
    $Usercom = Get-ADUser $User -Properties Company | Select-Object -ExpandProperty Company
    $UserP = "\\Server\$($Usercom)\$($Userdep)_Userhomes\$User"

    • Marked as answer by AndreH Tuesday, February 19, 2019 3:40 PM
    Tuesday, February 19, 2019 3:08 PM
  • you need no Powershell. Mark all User - right click - Properties

    Chris

    Tuesday, February 19, 2019 5:04 PM