-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
382 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<# | ||
# Copyright (c) 2014 All Rights Reserved by the SDL Group. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#> | ||
|
||
function Get-ISHNormalizedCredential | ||
{ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[pscredential]$Credentials | ||
) | ||
|
||
begin | ||
{ | ||
} | ||
|
||
process | ||
{ | ||
|
||
if($Credentials.UserName.StartsWith(".\")) | ||
{ | ||
Write-Warning "Credentials normalization.Replaced .\ with $env:COMPUTERNAME" | ||
New-Object System.Management.Automation.PSCredential($Credentials.UserName.Replace(".",$env:COMPUTERNAME),$Credentials.Password) | ||
} | ||
elseif($Credentials.UserName.indexOf("\") -lt 0) | ||
{ | ||
Write-Warning "Credentials normalization.Prefixed with $env:COMPUTERNAME" | ||
New-Object System.Management.Automation.PSCredential("$env:COMPUTERNAME\$($Credentials.UserName)",$Credentials.Password) | ||
} | ||
else | ||
{ | ||
$Credentials | ||
} | ||
} | ||
|
||
end | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<# | ||
# Copyright (c) 2014 All Rights Reserved by the SDL Group. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#> | ||
|
||
|
||
function Initialize-ISHRegistry | ||
{ | ||
[CmdletBinding()] | ||
param ( | ||
) | ||
|
||
begin | ||
{ | ||
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1 | ||
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet | ||
} | ||
|
||
process | ||
{ | ||
# http://docs.sdl.com/LiveContent/content/en-US/SDL%20Knowledge%20Center%20full%20documentation-v2/GUID-70BAEF73-D2B4-488B-8F71-505DB8ACB244 | ||
Write-Debug "Disabling Force Unload of registry" | ||
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Name DisableForceUnload -Value $true | ||
Write-Verbose "Disabled Force Unload of registry" | ||
} | ||
|
||
end | ||
{ | ||
|
||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
Source/Modules/ISHServer/Initialize-ISHUserLocalProfile.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<# | ||
# Copyright (c) 2014 All Rights Reserved by the SDL Group. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#> | ||
|
||
#requires -Module PoshPrivilege | ||
|
||
function Initialize-ISHUserLocalProfile | ||
{ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[pscredential]$OSUserCredentials | ||
) | ||
|
||
begin | ||
{ | ||
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1 | ||
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet | ||
} | ||
|
||
process | ||
{ | ||
$OSUserCredentials=Get-ISHNormalizedCredential -Credentials $OSUserCredentials | ||
$osUserName=$OSUserCredentials.UserName | ||
$osUserPassword=$OsUserCredentials.GetNetworkCredential().Password | ||
Write-Verbose "Normalized Credentials" | ||
Write-Debug "osUserName=$osUserName" | ||
|
||
$arguments=@( | ||
"-Command" | ||
"' { } '" | ||
) | ||
$powerShellPath=& C:\Windows\System32\where.exe powershell | ||
|
||
Write-Debug "powerShellPath=$powerShellPath" | ||
|
||
# Check if execution is within a remoting session | ||
if(Test-Path -Path Variable:\PSSenderInfo) | ||
{ | ||
$useScheduledTask=$true | ||
} | ||
# Check if execution is invoked by the Windows SYSTEM user. Typically for AWS CodeDeploy and UserData execution | ||
elseif($env:USERNAME -eq "NT AUTHORITY\SYSTEM") | ||
{ | ||
$useScheduledTask=$true | ||
} | ||
# Check if execution is invoked by the Windows SYSTEM user. Typically for AWS CodeDeploy and UserData execution | ||
elseif($env:USERNAME -eq "$($env:computername)`$") | ||
{ | ||
$useScheduledTask=$true | ||
} | ||
else | ||
{ | ||
$useScheduledTask=$false | ||
} | ||
Write-Debug "useScheduledTask=$useScheduledTask" | ||
|
||
# When the script is executing within a remoting session or from the Windows System user, we need to create and destroy a scheduled task that will force the user's profile initialization. | ||
if($useScheduledTask) | ||
{ | ||
Write-Verbose "Using a scheduled task to initialize $osUserName" | ||
|
||
Write-Debug "Added SeBatchLogonRight privilege to $osUserName" | ||
Add-Privilege -AccountName $osUserName -Privilege SeBatchLogonRight | ||
Write-Verbose "Added SeBatchLogonRight privilege to $osUserName" | ||
|
||
$taskName="Initialize $osUserName user profile" | ||
$argumentList=$arguments -join ' ' | ||
$command="Start-Process -FilePath powershell -LoadUserProfile -Wait -ArgumentList ""$argumentList""" | ||
$action = New-ScheduledTaskAction -Execute $powerShellPath -Argument "-Command '& { $command }'" | ||
Write-Debug "taskName=$taskName" | ||
Write-Debug "command=$command" | ||
Write-Debug "argumentList=$argumentList" | ||
Write-Debug "Register and starting Scheduled Task $taskName" | ||
$task = Register-ScheduledTask -TaskName $taskName -Action $action -User $osUserName -Password $osUserPassword | ||
Write-Verbose "Scheduled Task $taskName registered" | ||
|
||
Start-ScheduledTask -InputObject $task | ||
Write-Verbose "Scheduled Task $taskName started" | ||
|
||
$state=($task|Get-ScheduledTask).State | ||
Write-Debug "Scheduled Task $taskName state is $state." | ||
while($state -eq "Ready") | ||
{ | ||
Start-Sleep -Milliseconds 500 | ||
Write-Debug "Waiting for Scheduled Task $taskName" | ||
|
||
$state=($task|Get-ScheduledTask).State | ||
Write-Debug "Scheduled Task $taskName state is $state." | ||
} | ||
Write-Verbose "Scheduled Task $taskName removed" | ||
|
||
Write-Debug "Removing Scheduled Task $taskName" | ||
$task|Unregister-ScheduledTask -Confirm:$false | ||
Write-Verbose "Scheduled Task $taskName removed" | ||
|
||
Write-Debug "Removing SeBatchLogonRight privilege from $osUserName" | ||
Remove-Privilege -AccountName $osUserName -Privilege SeBatchLogonRight | ||
Write-Verbose "Removed SeBatchLogonRight privilege from $osUserName" | ||
} | ||
else | ||
{ | ||
Write-Verbose "Using a normal process to initialize $osUserName" | ||
Write-Debug "Starting process" | ||
Start-Process -FilePath $powerShellPath -ArgumentList $arguments -Credential $OsUserCredentials -LoadUserProfile -NoNewWindow -Wait | ||
Write-Verbose "Finished process" | ||
} | ||
} | ||
|
||
end | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.