Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

how to grab only username from get-credential

$
0
0

Hi guys, I’m creating a script to map network drives over a VPN connection. To connect to the network drives, I’m pulling credentials through get-credential.

write-host "Please enter your username and password." $mycredentials = get-credential -username domain.local New-PSDrive -Name Z -Root \server.domain.localmisc PSProvider filesystem -Credential $mycredentials -Persist -description "misc" 

This is all well and good. However, one of the drives I need to map is a user home folder, which is normally mapped to server.domain.localusers%username%

Is there any way for me to pull the username portion of the credential (the part that comes after domain.local) to pipe it into the network drive root path? Thanks for your help!

submitted by /u/mrnutcracker
[link] [comments]

The post how to grab only username from get-credential appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793