I was a little bored, so here you go:
## Example drive letter selection
# Only allow X, Y or <enter>
do{Write-Host -NoNewline -ForegroundColor Cyan "What drive letter do you prefer as a backup?"
$letter = (Read-Host -prompt "(X) or Y?").ToUpper()} while ($letter -notin @('x','y',''))
# This sets the default to X, allowing the user to simply press enter if X is OK.
if($letter -eq ''){$letter = 'X'}
# Now set the drive letter.
New-PSDrive âName $letter âPSProvider FileSystem âRoot â\\server\backupâ âPersist -ErrorAction SilentlyContinue
Basic drive letter set is done, but we can be more complicated:
# Do actions based on a user that has an network location from IP.
$ipaddr = Get-NetIPAddress|?{$_.SuffixOrigin -eq "Dhcp" -and $_.AddressState -like "*preferred*"}|select -ExpandProperty ipaddress
# Set the preferred drive letter.
$letter = X
If($ipaddr -like '192.168.0.*'){
New-PSDrive âName $letter âPSProvider FileSystem âRoot â\\alpha\backupâ âPersist -ErrorAction SilentlyContinue
Write-Host -ForegroundColor Green "You're in Alpha!`nBackup drive connected to Alpha site.`nHave a sumptuous day!"
}
# if you have more networks, insert here with more if statements.
Else{
New-PSDrive âName $letter âPSProvider FileSystem âRoot â\\bravo\backupâ âPersist -ErrorAction SilentlyContinue
Write-Host -ForegroundColor Green "You're in Bravo!`nBackup drive connected to Bravo site.`nHave a sumptuous day!"
}