Skip to content

Commit bceaad1

Browse files
committed
Adding executionpolicy change command
1 parent e7ca8af commit bceaad1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

setup/Setup/SetExecutionPolicy.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
Get-ExecutionPolicy -List | Where-Object {$_.ExecutionPolicy -eq "Restricted"} |
16+
% {
17+
try
18+
{
19+
Set-ExecutionPolicy -Scope $_.Scope -ExecutionPolicy RemoteSigned -Force -ErrorAction "SilentlyContinue"
20+
}
21+
catch
22+
{
23+
# do not fail if execution policy cannot be set for this scope
24+
}
25+
}

setup/azurecmd.wxs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
</Component>
9494
</DirectoryRef>
9595

96+
<DirectoryRef Id="PowerShellFolder">
97+
<Component Id="AzureSdkExecutionPolicyScript" Guid="3d0d589a-b34c-4c48-9a4c-df78f286c6a3">
98+
<File Id="AzureSdkExecutionPolicyScriptFile" KeyPath="yes" Source="$(var.SolutionDir)\Setup\SetExecutionPolicy.ps1" />
99+
</Component>
100+
</DirectoryRef>
101+
96102
<DirectoryRef Id="AzureSdkMenu">
97103
<Component Id="AzureSdkShortcut" Guid="A9B58A22-F746-451D-8840-F887D8014C3C">
98104
<Shortcut Id="AzureSdkStartMenuShortcut"
@@ -110,13 +116,14 @@
110116
<ComponentGroupRef Id="azurecmdfiles" />
111117
<ComponentRef Id="PSModulePath.System" />
112118
<ComponentRef Id="AzureSdkShortcut" />
119+
<ComponentRef Id="AzureSdkExecutionPolicyScript" />
113120
</Feature>
114121

115122
<Binary Id="CustomActions" SourceFile="$(var.caSourceDir)\Microsoft.WindowsAzure.Setup.CA.dll"/>
116123
<CustomAction Id="UpdatePSShortcut" BinaryKey="CustomActions" DllEntry="UpdatePSShortcut" Execute ="deferred" Impersonate="no"/>
117124
<CustomAction Id="SetCustomActionDataValue" Return="check" Property="UpdatePSShortcut"
118125
Value="ShortcutPath=[AzureSdkMenu]Microsoft Azure PowerShell.lnk;DefaultShortcutPath=[ProgramMenuFolder]System Tools\Windows PowerShell.lnk" />
119-
<CustomAction Id="SetExecutionPolicy" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -Command &quot;Set-ExecutionPolicy RemoteSigned -Scope LocalMachine -Force&quot;" Execute="deferred" Impersonate="no" Return="check"/>
126+
<CustomAction Id="SetExecutionPolicy" Property="POWERSHELLEXE" ExeCommand="-NoLogo -NoProfile -ExecutionPolicy Bypass -Command &quot;.\&quot;[PowerShellFolder]\SetExecutionPolicy.ps1&quot;&quot;" Execute="deferred" Impersonate="no" Return="check"/>
120127

121128
<InstallExecuteSequence>
122129
<Custom Action="SetCustomActionDataValue" After="CreateShortcuts">NOT Installed</Custom>

0 commit comments

Comments
 (0)