Skip to content

Commit

Permalink
Refactor users
Browse files Browse the repository at this point in the history
- Move Windows User stuff to SetupWindowsUsers
- create password in setupVariables
- Support Server Manager connection to container
  • Loading branch information
freddydk committed Sep 4, 2017
1 parent 89e3b15 commit 13d95d3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
10 changes: 0 additions & 10 deletions Run/SetupNavUsers.ps1
Expand Up @@ -7,11 +7,6 @@
#

if ($auth -eq "Windows") {
if ($passwordSpecified -and ($username -ne "")) {
Write-Host "Create Windows user"
New-LocalUser -AccountNeverExpires -FullName $username -Name $username -Password (ConvertTo-SecureString -AsPlainText -String $password -Force) -ErrorAction Ignore | Out-Null
Add-LocalGroupMember -Group administrators -Member $username -ErrorAction Ignore
}
if ($username -ne "") {
if (!(Get-NAVServerUser -ServerInstance NAV | Where-Object { $_.UserName.EndsWith("\$username", [System.StringComparison]::InvariantCultureIgnoreCase) -or $_.UserName -eq $username })) {
Write-Host "Create NAV user"
Expand All @@ -20,13 +15,8 @@ if ($auth -eq "Windows") {
}
}
} else {
if ($username -eq "") { $username = "admin" }
if (!(Get-NAVServerUser -ServerInstance NAV | Where-Object { $_.UserName -eq $username })) {
New-NavServerUser -ServerInstance NAV -Username $username -Password (ConvertTo-SecureString -String $password -AsPlainText -Force)
New-NavServerUserPermissionSet -ServerInstance NAV -username $username -PermissionSetId SUPER
if (!$passwordSpecified) {
Write-Host "NAV Admin Username : $username"
Write-Host "NAV Admin Password : $password"
}
}
}
8 changes: 5 additions & 3 deletions Run/SetupSqlUsers.ps1
Expand Up @@ -9,10 +9,12 @@

if ($databaseServer -eq "localhost" -and $databaseInstance -eq "SQLEXPRESS") {

$sqlcmd = "ALTER LOGIN sa with password=" +"'" + $password + "'" + ",CHECK_POLICY = OFF;ALTER LOGIN sa ENABLE;"
& sqlcmd -S 'localhost\SQLEXPRESS' -Q $sqlcmd
if ($password -ne "") {
$sqlcmd = "ALTER LOGIN sa with password=" +"'" + $password + "'" + ",CHECK_POLICY = OFF;ALTER LOGIN sa ENABLE;"
& sqlcmd -S 'localhost\SQLEXPRESS' -Q $sqlcmd
}

if ($username.Contains('\') -and $auth -eq "Windows") {
if ($auth -eq "Windows" -and $username -ne "" -and $password -eq "") {
$sqlcmd =
"IF NOT EXISTS
(SELECT name
Expand Down
10 changes: 7 additions & 3 deletions Run/SetupVariables.ps1
Expand Up @@ -7,12 +7,16 @@ if ($auth -eq "") {
}
}
$username = "$env:username"
if ($username -eq "ContainerAdministrator") {
$username = ""
if ($username -eq "ContainerAdministrator") { $username = "" }
if ($auth -ne "Windows") {
if ($username -eq "") { $username = "admin" }
}

$password = "$env:password"
$passwordSpecified = ($password -ne "")
if (!$passwordSpecified) { $password = Get-RandomPassword }
if ($auth -ne "Windows") {
if (!$passwordSpecified) { $password = Get-RandomPassword }
}

$licensefile = "$env:licensefile"

Expand Down
14 changes: 14 additions & 0 deletions Run/SetupWindowsUsers.ps1
@@ -0,0 +1,14 @@
# INPUT
# $auth
# $username (optional)
# $password (optional)
#
# OUTPUT
#

if ($password -ne "" -and $username -ne "") {
Write-Host "Create Windows user"
New-LocalUser -AccountNeverExpires -FullName $username -Name $username -Password (ConvertTo-SecureString -AsPlainText -String $password -Force) -ErrorAction Ignore | Out-Null
Add-LocalGroupMember -Group administrators -Member $username -ErrorAction Ignore
}

5 changes: 5 additions & 0 deletions Run/navstart.ps1
Expand Up @@ -322,6 +322,7 @@ if ($runningGenericImage -or $runningSpecificImage) {
. (Get-MyFilePath "SetupFileShare.ps1")
}

. (Get-MyFilePath "SetupWindowsUsers.ps1")
. (Get-MyFilePath "SetupSqlUsers.ps1")
. (Get-MyFilePath "SetupNavUsers.ps1")
}
Expand All @@ -347,6 +348,10 @@ if (!$buildingImage) {
$publicWebBaseUrl = $CustomConfig.SelectSingleNode("//appSettings/add[@key='PublicWebBaseUrl']").Value
Write-Host "Web Client : $publicWebBaseUrl"
}
if ($auth -ne "Windows" -and !$passwordSpecified) {
Write-Host "NAV Admin Username : $username"
Write-Host "NAV Admin Password : $password"
}
if ($httpSite -ne "N") {
if (Test-Path -Path (Join-Path $httpPath "*.vsix")) {
Write-Host "Dev. Server : $protocol$hostname"
Expand Down

0 comments on commit 13d95d3

Please sign in to comment.