Skip to content

Commit 20f678d

Browse files
RobRob
Rob
authored and
Rob
committed
running as another user
1 parent 447e44f commit 20f678d

File tree

3 files changed

+176
-72
lines changed

3 files changed

+176
-72
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"metadata": {
3+
"kernelspec": {
4+
"name": ".net-powershell",
5+
"display_name": ".NET (PowerShell)"
6+
},
7+
"language_info": {
8+
"name": "PowerShell",
9+
"version": "7.0",
10+
"mimetype": "text/x-powershell",
11+
"file_extension": ".ps1",
12+
"pygments_lexer": "powershell"
13+
}
14+
},
15+
"nbformat_minor": 2,
16+
"nbformat": 4,
17+
"cells": [
18+
{
19+
"cell_type": "markdown",
20+
"source": [
21+
"# Opening Programmes with other credentials using Secret Management\r\n",
22+
"\r\n",
23+
"It is good practice to not log into your work station with an account with admin privileges. In many shops, you will need to open programmes that can do administration tasks with another user account credentials. unfortunately, people being people, they will often store their admin account credentials in a less than ideal manner (OneNote, Notepad ++ etc) so that when they right click and run as a different user, they can copy and paste the password.\r\n",
24+
"\r\n",
25+
"## Use the Secret Management module\r\n",
26+
"\r\n",
27+
"You can use the Secret Management module to do this. See the [Secrets_Management_with_PowerShell](Secrets_Management_with_PowerShell.ipynb) notebook to show how to install the module and add secrets.\r\n",
28+
"\r\n",
29+
"## Using my admin account\r\n",
30+
"\r\n",
31+
"I have an admin account called `THEBEARD\\fatherjack`\r\n",
32+
"\r\n",
33+
"I am going to add the user account to my LocalVault"
34+
],
35+
"metadata": {
36+
"azdata_cell_guid": "eda16b16-6fd1-4006-8547-e9fe07ff67d2"
37+
}
38+
},
39+
{
40+
"cell_type": "code",
41+
"source": [
42+
"$Secret = Read-Host \"tell me your secret\" -AsSecureString\r\n",
43+
"Set-Secret -Name THEBEARD\\fatherjack-Secret $Secret"
44+
],
45+
"metadata": {
46+
"azdata_cell_guid": "f5f3eff1-f80d-43c4-be6a-c352118c9b75"
47+
},
48+
"outputs": [],
49+
"execution_count": 14
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"source": [
54+
"## Opening Programmes as my admin user\r\n",
55+
"\r\n",
56+
"With the password in the vault, I can now use `Start-Process` with the `-Credential` parameter to run those programmes as my admin user."
57+
],
58+
"metadata": {
59+
"azdata_cell_guid": "772b5a91-7bb2-4264-a17f-13819569257a"
60+
}
61+
},
62+
{
63+
"cell_type": "code",
64+
"source": [
65+
"$fatherjack = New-Object System.Management.Automation.PSCredential ('THEBEARD\\fatherjack',(Get-Secret -Name 'THEBEARD\\fatherjack'))\n",
66+
"Start-Process code -Credential $fatherjack\n",
67+
"Start-Process ssms -Credential $fatherjack\n",
68+
"Start-Process azuredatastudio -Credential $fatherjack\n",
69+
""
70+
],
71+
"metadata": {
72+
"azdata_cell_guid": "18f083e9-c944-44d6-b970-f0583b372d81"
73+
},
74+
"outputs": [],
75+
"execution_count": 3
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"source": [
80+
"![runas](runas.png)"
81+
],
82+
"metadata": {
83+
"azdata_cell_guid": "3911b4f1-34a5-4e86-a925-fc08581b53e7"
84+
}
85+
}
86+
]
87+
}

0 commit comments

Comments
 (0)