Skip to content

Commit 5439ede

Browse files
committed
Fixed convert cred. to PSCred. warning
1 parent f13d0c5 commit 5439ede

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

dep/_MainConnect.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ param (
2121
[Parameter()]
2222
[string]$VPN_User
2323
)
24-
$PhoneBookLocation = ".\dep\$VPN_Name.pbk"
24+
$PhoneBookLocation = ".\dep\Phonebooks\$VPN_Name.pbk"
2525

2626

2727
#Debug:
2828
# $RDP_Address = ""
29-
# $RDP_Username = """
29+
# $RDP_Username = ""
3030
# $RDP_Port = "" #Viss denne er tom brukes standard port
3131
# $RDP_Server_IP = "" #Må være IP addresse
3232
# $VPN_Name = "" #Navnet til VPN tilkoblingen i .dep\Phonebook.pbk
@@ -38,7 +38,7 @@ function New-Credidential {
3838
#RDP Passord
3939
$RDPPasswordsec = Read-Host -Prompt "Passord for $VPN_Name (RDP og VPN)" -AsSecureString
4040
$RDPPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($RDPPasswordsec))
41-
New-StoredCredential -Target $RDP_Server_IP -UserName $RDP_Username -Password $RDPPassword -Persist 'LocalMachine'
41+
New-StoredCredential -Target $RDP_Server_IP -UserName $RDP_Username -Password $RDPPassword -Persist 'LocalMachine' -Comment $VPN_Name
4242

4343
# #VPN Passord
4444
# $VPNPWSameAsRDP = Read-Host -Prompt "Er passordet for VPN det samme som RDP? Y/N"
@@ -62,7 +62,7 @@ if (-Not (Get-Module -ListAvailable -Name CredentialManager)) {
6262

6363

6464
#Lager en ny credential i Windows Legitimasjonsenter, viss den ikke finnes fra før.
65-
if ($null -eq (Get-StoredCredential -Target "$RDP_Server_IP")) {
65+
if ($null -eq (Get-StoredCredential -Target $RDP_Server_IP -AsCredentialObject)) {
6666
$RDPPassword = New-Credidential #Returns Passwordc
6767
$RDPPassword = $RDPPassword[1]
6868
}
@@ -77,8 +77,9 @@ if ([string]::IsNullOrEmpty($VPN_User) -or [string]::IsNullOrEmpty($VPNPassword)
7777
Write-Host "Using RDP Username as VPN Username"
7878
}
7979
if ([string]::IsNullOrEmpty($VPNPassword)) {
80-
$VPNPassword = Get-StoredCredential -Target $RDP_Server_IP
81-
$VPNPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($VPNPassword.Password))
80+
$VPNPassword = Get-StoredCredential -Target $RDP_Server_IP -AsCredentialObject
81+
# $VPNPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($VPNPassword.Password))
82+
$VPNPassword = $VPNPassword.Password
8283
Write-Host "Using RDP Password as VPN Password"
8384
}
8485
}

0 commit comments

Comments
 (0)