Thursday, 16 January 2020

cmd - query certain KB on bulk computers

@echo off

set KB=4534273
set LISTFILE=computers.txt


echo --------------------  >> %kb%.txt
echo %date% - %time%  >> %kb%.txt
echo --------------------  >> %kb%.txt

for /f %%a in (%LISTFILE%) do (
    echo.
    echo ---------------------------------------
    echo.
    echo %%a
    ping -n 1 %%a | find "TTL="
    if not errorlevel 1 (
        wmic /Node:%%a qfe list | find "%KB%"

        if not errorlevel 1 (
            echo %%a kb%kb% is installed >> %kb%.txt
        ) else (
            echo %%a kb%kb% is NOT installed >> %kb%.txt
        )
    ) else (
        echo %%a unavailable >> %kb%.txt
    )
)

pause

cmd - schedule reboot one in the night on multiple computers

@echo off

set LISTFILE=scheduledtask.txt


echo --------------------  > %LISTFILE%.log
echo %date% - %time%  >> %LISTFILE%.log
echo --------------------  >> %LISTFILE%.log

for /f %%a in (%LISTFILE%) do (
    echo.
    echo ---------------------------------------
    echo.
    echo %%a

    SCHTASKS /S %%a /CREATE /SC ONCE /TN "YourFolder\reboot once" /TR "shutdown -r" /sd 01/17/2020 /ST 04:00 /RU "System" /F | find "SUCCESS"

        if not errorlevel 1 (
            echo %%a task was scheduled >> %LISTFILE%.log
        ) else (
            echo %%a task was NOT scheduled >> %LISTFILE%.log
        )
)


pause

Friday, 3 January 2020

powershell - gpo report remote computer


If the a user complains the logon takes to much time, you can run this powershell command


Get-GPResultantSetOfPolicy -user nordsoncorp\targetuseraccount -Computer targetcomputername -ReportType Html -Path C:\Temp\RSOPBericht.html

In the html file you will find what slows down the login

CMD - get clipboard text

for /f "eol=; tokens=*" %I in ('powershell Get-Clipboard') do set CLIPBOARD_TEXT=%I

CMD - delete empty subfolders

cmd to the folder where you want to delete empty subfolders

run this connamd

for /f "delims=" %i in ('dir /s /b /ad ^| sort /r') do rd "%i" 2>NUL

Powershell - install RSAT on Winodws 10


methode 1:

DISM.exe /Online /add-capability /CapabilityName:Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 /CapabilityName:Rsat.BitLocker.Recovery.Tools~~~~0.0.1.0 /CapabilityName:Rsat.CertificateServices.Tools~~~~0.0.1.0 /CapabilityName:Rsat.DHCP.Tools~~~~0.0.1.0 /CapabilityName:Rsat.Dns.Tools~~~~0.0.1.0 /CapabilityName:Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0 /CapabilityName:Rsat.FileServices.Tools~~~~0.0.1.0 /CapabilityName:Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0 /CapabilityName:Rsat.IPAM.Client.Tools~~~~0.0.1.0 /CapabilityName:Rsat.LLDP.Tools~~~~0.0.1.0 /CapabilityName:Rsat.NetworkController.Tools~~~~0.0.1.0 /CapabilityName:Rsat.NetworkLoadBalancing.Tools~~~~0.0.1.0 /CapabilityName:Rsat.RemoteAccess.Management.Tools~~~~0.0.1.0 /CapabilityName:Rsat.RemoteDesktop.Services.Tools~~~~0.0.1.0 /CapabilityName:Rsat.ServerManager.Tools~~~~0.0.1.0 /CapabilityName:Rsat.Shielded.VM.Tools~~~~0.0.1.0 /CapabilityName:Rsat.StorageReplica.Tools~~~~0.0.1.0 /CapabilityName:Rsat.VolumeActivation.Tools~~~~0.0.1.0 /CapabilityName:Rsat.WSUS.Tools~~~~0.0.1.0 /CapabilityName:Rsat.StorageMigrationService.Management.Tools~~~~0.0.1.0 /CapabilityName:Rsat.SystemInsights.Management.Tools~~~~0.0.1.0


 
methode 2:

Get-WindowsCapability -Online | ? {$_.Name -like "*RSAT*" -and $_.State -eq "NotPresent"} | Add-WindowsCapability -Online

CMD - install software on remote computer with wmic


@echo off

set LISTFILE=computers.txt

for /f %%a in (%LISTFILE%) do (
echo.
echo ---------------------------------------
echo.
echo %%a
ping -n 1 %%a | find "TTL="
if not errorlevel 1 (
echo copy your setup.exe to %%a
if not exist "\\%%a\c$\temp\" mkdir "\\%%a\c$\temp\"
if NOT exist "\\%%a\c$\temp\setup.exe" xcopy "C:\source-temp\setup.exe" "\\%%a\c$\temp\" /Y
wmic /Node:%%a process call create "\\%%a\c$\temp\setup.exe  /quiet /norestart"

)

)

CMD - find wifi wlan key on windows computer


netsh wlan show profile

netsh wlan show profile targetwifiprofilename key=clear

Powershell - Windows - share all subfolders

if you want to share all subfolders below one folder like

homedirectories\username




Share all subfolders

Get-ChildItem | Where-Object { $_.PSIsContainer } | ForEach-Object { Invoke-Expression -Command ([string]::concat("net share ",$_,"=",(Get-Location).Path$,"\",$_," ""/GRANT:Everyone,FULL"" ""/USERS:20"""))}


Share all subfolders as hidden

Get-ChildItem | Where-Object { $_.PSIsContainer } | ForEach-Object { Invoke-Expression -Command ([string]::concat("net share ",$_,"$","=",(Get-Location).Path,"\",$_," ""/GRANT:Everyone,FULL"" ""/USERS:20"""))}




Active directory - add group managed by


a shortcut with
 
rundll32 dsquery,OpenQueryWindow

allows the user to manage an AD group, if he is the "group manager"