Skip to content

Instantly share code, notes, and snippets.

@mdanshin
mdanshin / Get-ManagerCanUpdatedMembershipList
Created September 20, 2023 09:34
Get all Active Directory groups with Manager Can Updated Membership List checkbox.
$groups = Get-ADGroup -Filter *
$result = @()
foreach ( $group in $groups ) {
$object = Get-ADObject `
-Identity $group.DistinguishedName `
-Properties managedBy
if ( $object.managedBy -ne $null ) {
$managedBy = Get-ADUser -Filter "DistinguishedName -eq '$($object.managedBy)'"
@mdanshin
mdanshin / get-rdpconnections.ps1
Created August 10, 2023 15:46
Получение статистики RDP подключений
# Задание имени журнала событий, из которого будем получать данные.
$LogName = 'Microsoft-Windows-TerminalServices-LocalSessionManager/Operational'
# Имя пользователя, для которого не будем обрабатывать события.
$ExcludedUsername = "DOMAIN\username"
# Имя компьютера, с которого получаем события.
$ComputerName = "localhost"
# Определение функции IP2Name для преобразования IP-адреса в имя хоста с помощью Resolve-DnsName.
@mdanshin
mdanshin / App.jsx
Last active May 3, 2023 06:41
Пример использования контекста в React
import React, { createContext, useContext } from 'react';
// Создаем контекст со значением по умолчанию "default"
const MyContext = createContext('default');
// Создаем компонент, который получает значение контекста и отображает его в диве
function MyComponent() {
const value = useContext(MyContext);
return <div>{value}</div>;
}
git config --global user.name "Mikhail Danshin"
git config --global user.email mdanshin@gmail.com
git init
git checkout -b main #In October 2020, GitHub has changed its naming convention for the default branch from master to main.
git remote add origin https://gitlab.danshin.ms/mdanshin/cicd-test.git
git add .
git commit -m "Initial commit"
git -c http.sslVerify=false push -u origin main
@mdanshin
mdanshin / readme.md
Last active November 17, 2021 19:55
Autostart docker on wsl2

Create line in sudo visudo (at WSL to prevent asking password):

  %sudo   ALL=(ALL) NOPASSWD: /usr/sbin/service docker start

Add in ~/.bashrc

# Start Docker daemon automatically when logging in if not running.
@mdanshin
mdanshin / index.js
Last active October 30, 2021 12:39
Return value from eventEmitter
import EventEmitter from "events";
class Service {
getAllUsers() {
let search = function () {
return new Promise((resolve, reject) => {
let arr = []
const myEmitter = new EventEmitter()
myEmitter.on("event", () => {
arr.push(1,2,4,8)
@mdanshin
mdanshin / sidToString.js
Created October 23, 2021 17:39
Translate LDAP objectSID from base64 fromat (AQUAAAAAAAUVAAAA6We7mNa317+CBR5sKAYAAA==) to SSDL (S-1-5-21-2562418665-3218585558-1813906818-1576)
sidToString(base64) {
const buffer = Buffer.from(base64, 'base64')
const array = buffer.toString('hex')
const G = array.toString().match(/.{1,2}/g)
const BESA2=`${G[8]}${G[9]}${G[10]}${G[11]}`
const BESA3=`${G[12]}${G[13]}${G[14]}${G[15]}`
const BESA4=`${G[16]}${G[17]}${G[18]}${G[19]}`
const BESA5=`${G[20]}${G[21]}${G[22]}${G[23]}`
const BERID=`${G[24]}${G[25]}${G[26]}${G[27]}`
@mdanshin
mdanshin / .env
Last active October 17, 2021 19:49
MERN server template
PORT=5000
@mdanshin
mdanshin / form.js
Created March 21, 2020 09:38
POST data to back-end
import React, {useState} from "react";
export default function Create() {
const [state, setState] = useState()
function changeHandler(event) {
const {name, value} = event.target
setState(prevState => ({
...prevState,