Some tips for me and other

Powershell + Get installed software

get-ciminstance win32_product | select name | sort-object name

BSOD 0x0000007B Windows 7 / Windows Server 2008 R2 – 2

Source: CLASSPNP.SYS. HKEY_LOCAL_MACHINE  File -> Load Hive.  \Windows\System32\config\SYSTEM. HKEY_LOCAL_MACHINE\local_hkey\ControlSet001\services\. Atapi Intelide LSI_SAS REG_DWORD Start  0 (0x00000000). HKEY_LOCAL_MACHINE\local_hkey и в меню выбрать Unload Hive. HKEY_LOCAL_MACHINE\local_hkey\ControlSet001\services Service VMWare Windows x64  SATA RAID aliide 3 3 3 amdide 3 3 3 atapi 0 0 0 cmdide 3 3 3 iastorv 3 3 3 intelide 0 3 3 […]

Python + generating images + text

Source: Install the library: sudo pip install pillow The code: #!/usr/bin/env python from PIL import Image, ImageDraw, ImageFont # Text positioning text_y = 100 text_pad = 45 # Define fonts for regular text and heading data_font = ImageFont.truetype(“Roboto-Regular.ttf”, 32) header_font = ImageFont.truetype(“Roboto-Bold.ttf”, 50) # Load background image bg_img =“bg_img.png”) surface = ImageDraw.Draw(bg_img) # […]

Powershell + Mikrotik backups

Source: #зададим политику сразу, чтобы не вспминать команду при переносе Set-ExecutionPolicy remotesigned -scope currentuser #установка и импорт библиотеки для ssh Install-Module -Name Posh-SSH Import-Module posh-ssh $curDir = $MyInvocation.MyCommand.Definition | split-path -parent function bkprtr { param($ipaddr) #тут указываем логин и пароль к роутерам с правами на ftp и ssh. $secpasswd = ConvertTo-SecureString “Ваш_пароль_к_роутеру” -AsPlainText -Force […]

Hyper-V + VLANs

Adding VLAN with shell: Add-VMNetworkAdapter -SwitchName Switch -VMName “VmName” -Name “TrunkNic” Set-VMNetworkAdapterVlan -Trunk -AllowedVlanIdList “100,101” -VMName “VmName” -VMNetworkAdapterName “TrunkNic” -NativeVlanId 1

Powershell + Users in OU but not in the groups

import-module ActiveDirectory #$groups = ‘group1′,’group2′,’group3’ $groups = ‘mygroup’ $notpresent = @() $ourset = @{} foreach ($group in $groups) { $members = (get-group $group).members foreach ($member in $members) { if ( !$ourset.contains($member.distinguishedname) ) { $ourset.($member.distinguishedname) = $true } } } get-recipient -OrganizationalUnit MyOU | foreach { if ( !$ourset.contains($_.distinguishedname) ) { $notpresent += $_ } } […]

Supermicro IPMI + Reset password

If you have physical access to the server, follow these simple steps to reset the ADMIN password on your IPMI: Create a bootable DOS USB stick using. Download the latest IPMICFG utility released by Supermicro. Extract the archive and copy the contents of the ‘DOS’ folder on to your bootable DOS USB. Boot your server […]

Replace a line in a file with SED

sed -i ‘Ns/.*/replacement-line/’ file.txt where N should be replaced by your target line number. This replaces the line in the original file. To save the changed text in a different file, drop the -i option: sed ‘Ns/.*/replacement-line/’ file.txt > new_file.txt

Powershell + Replace user’s manager

$userobj = Get-ADObject -SearchBase “DC=local, DC=com” -Filter {objectClass -eq “user” -and objectCategory -eq “person” -and manager -eq “CN=manager,DC=local,DC=com”} -Properties name, manager, department foreach ($user in $userobj) { Set-ADObject -Identity $user -replace @{“manager”=”CN=manager2,DC=local,DC=com”} write-host $, $user.manager }

Windows + Remote commands

Psexec from sysinternals suite. WMIC: wmic /node:”servername” qfe get hotfixid | find “KB4012212″, wmic /node:”servername” process call create “cmd /c somecommands” Powershell, run Enable-PSRemoting-Force on the remote PC, run Test-WSMan on your PC to test the connection, run Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME Enter-PSSession, as in the #3. Other tools.

Previous Posts