Skip to content

Commit 76a8100

Browse files
KedidiKedidi
authored andcommitted
PowerShell Script
1 parent f56618a commit 76a8100

File tree

8 files changed

+271
-1
lines changed

8 files changed

+271
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# devops-python-script
1+
# DevOps& SysAdmin tasks with Python, Bash, PowerShell and Go
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Script PowerShell
2+
3+
# Giving service account or application access to EventLog Windows.
4+
5+
$eventLog_key = "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog"
6+
$security_key = "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Security"
7+
$user = "your service account name"
8+
9+
$acl_eventLog = Get-Acl $eventLog_key
10+
$acl_security = Get-Acl $security_key
11+
12+
# Create the identity
13+
$idRef = [System.Security.Principal.NTAccount]($user)
14+
15+
# Create a System.Security.AccessControl.RegistryRights object using the appropriate rights
16+
$regRights = [System.Security.AccessControl.RegistryRights]::FullControl
17+
18+
# InheritanceFlags Enum (ContainerInherit | None | ObjectInherit)
19+
# https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.inheritanceflags?view=netframework-4.8
20+
$inhFlags = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit
21+
22+
$prFlags = [System.Security.AccessControl.PropagationFlags]::None
23+
24+
# AccessControlType Enum (Allow | Deny)
25+
# https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.accesscontroltype?view=netframework-4.8
26+
$acType = [System.Security.AccessControl.AccessControlType]::Allow
27+
28+
29+
# Create the RegistryAccessRule object using all of the objects collected
30+
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($idRef, $regRights, $inhFlags, $prFlags, $acType)
31+
32+
33+
# Add the RegistryAccessRule created in the previous section to the current ACL using the AddAccessRule()
34+
$acl_eventLog.AddAccessRule($rule)
35+
36+
# Commit the new ACL
37+
$acl_eventLog | Set-Acl -Path $eventLog_key
38+
39+
40+
$acl_security.AddAccessRule($rule)
41+
42+
$acl_security | Set-Acl -Path $security_key
43+
44+
Write-Debug "registry access rule has been applied"
45+
46+
# (Get-Acl $eventLog_key).Access
47+
48+
# (Get-Acl $security_key).Access

powershell/manage_acl_registry.ps1

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Script PowerShell
2+
3+
# Add & Remove ACL from Windows Registry Key via Powershell.
4+
5+
function AddPermission($key, $user) {
6+
7+
$acl = Get-Acl $key
8+
9+
# Create the identity
10+
$idRef = [System.Security.Principal.NTAccount]($user)
11+
12+
# Create a System.Security.AccessControl.RegistryRights object using the appropriate rights
13+
$regRights = [System.Security.AccessControl.RegistryRights]::FullControl
14+
15+
# InheritanceFlags Enum (ContainerInherit | None | ObjectInherit)
16+
# https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.inheritanceflags?view=netframework-4.8
17+
$inhFlags = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit
18+
19+
$prFlags = [System.Security.AccessControl.PropagationFlags]::None
20+
21+
# AccessControlType Enum (Allow | Deny)
22+
# https://docs.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.accesscontroltype?view=netframework-4.8
23+
$acType = [System.Security.AccessControl.AccessControlType]::Allow
24+
25+
26+
# create the RegistryAccessRule object using all of the objects collected
27+
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($idRef, $regRights, $inhFlags, $prFlags, $acType)
28+
29+
30+
# Add the RegistryAccessRule created in the previous section to the current ACL using the AddAccessRule()
31+
$acl.SetAccessRule($rule)
32+
33+
# Commit the new ACL
34+
$acl | Set-Acl -Path $key
35+
36+
Write-Host "`n registry access rule has been applied `n " -ForegroundColor Green
37+
38+
(Get-Acl $key).Access
39+
40+
}
41+
42+
function DeletePermission($key, $user, $domane) {
43+
44+
$acl = Get-Acl $key
45+
Write-Output $acl.access
46+
47+
$rules = $acl.access | Where-Object {
48+
$_.IdentityReference -like "$domane\$user"
49+
}
50+
51+
ForEach($rule in $rules) {
52+
$acl.RemoveAccessRule($rule) | Out-Null
53+
Write-Host "`n rule deleted `n" -ForegroundColor Red
54+
}
55+
56+
Set-ACL -Path $key -AclObject $acl
57+
}
58+
59+
60+
$security_key = "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Security"
61+
$user = $args[0]
62+
$domaine = $domaine[1]
63+
64+
DeletePermission $security_key $user $domaine
65+
AddPermission $security_key $user

python/.gitignore

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

python/domain_to_ip.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
# Get ip address of any website using socket.
4+
5+
6+
# Import the necessary packages!
7+
import socket as socket
8+
9+
# Get my local hostname
10+
my_hostname = socket.gethostname()
11+
12+
# Display my hostname
13+
print('Your hostname is: ' + my_hostname)
14+
15+
# Get my local ip adress
16+
my_ip = socket.gethostbyname(my_hostname)
17+
18+
# Display my ip
19+
print('Your ip address is: ' + my_ip)
20+
21+
# Input the domain name
22+
host = input('Enter the domain name, example (python.org): ')
23+
24+
# Fetch the ip
25+
ip = socket.gethostbyname(host)
26+
27+
# Display the ip
28+
print('The ip address of ' + host + ' is: ' + ip)
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)