Thursday, 21 August 2014

Registry - confirm file delete on windows 2012 (R2) , 8 or 8.1

Hive HKEY_LOCAL_MACHINE
Key path SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer
Value name ConfirmFileDelete
Value type REG_DWORD
Value data 0x1 (1)

Registry - disable EOS end of support notification for XP

Hive HKEY_LOCAL_MACHINE
Key path SOFTWARE\Microsoft\Windows\CurrentVersion
Value name DisableEOSNotification
Value type REG_DWORD
Value data 0x1 (1)

VBS - create local administrator "useradmin" with SN serialnumber as password

' created by Martin Junge 14.5.2012
' the script creates a local Administrator "UserAdmin"
' Password is the individual "Dell Service Tag" + "?"

Dim objWMI : Set objWMI = GetObject("winmgmts:")
Dim colSettingsComp : Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem")
Dim colSettingsBios : Set colSettingsBios = objWMI.ExecQuery("Select * from Win32_BIOS")
Dim objComputer, strModel, strSerial
For Each objComputer in colSettings
  strModel = objComputer.Model
Next
For Each objComputer in colSettingsBios
  strSerial = objComputer.SerialNumber
Next

'wscript.echo strSerial


accUserName = "Useradmin"
accUserPass = strSerial & "?"

            QueryForUser(accUserName)
                'this section creates the new username if it doesn't exist
                Set objNetwork = CreateObject("Wscript.Network")
                strComputer = objNetwork.ComputerName
                Set objComputer = GetObject("WinNT://" &strComputer)

                Set colAccounts = GetObject("WinNT://" & strComputer & "")
                Set objUser = colAccounts.Create("user", accUserName)
                objUser.SetPassword accUserPass
                objUser.Put "UserFlags", 65600 '
                objUser.SetInfo

                'add user to administrators group

                'Set objGroup = GetObject("WinNT://" & strComputer & "/Administratoren,group")
                'Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ",user")
                'objGroup.Add(objUser.ADsPath)

           'msgbox "username was created"

                'this section just changes the password if the user exists
                Sub QueryForUser(strUserName)
                    Set objlocal = GetObject("WinNT://.")
                    objlocal.Filter = Array("user")
                    For Each User In objlocal
                    If lcase(User.Name) = lcase(strUserName) Then
                        strComputer = "."
                        Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ", user")
                        objUser.SetPassword accUserPass
                        objUser.SetInfo
                        'msgbox User.Name & " already exists." & vbCrLf & "The password was re-set."
                        WScript.Quit
                    End If   
            Next
                    End Sub

Powershell - get all mailboxes size from exchange server

get-mailbox -server yourexchangeservername -ResultSize unlimited | select-object Alias, IssueWarningQuota, ProhibitSendQuota, @{label="TotalItemSize(MB)";expression={(get-mailboxstatistics $_).TotalItemSize.Value.ToMB()}}, @{label="ItemCount";expression={(get-mailboxstatistics $_).ItemCount}}, Database | Export-Csv "UserMailboxSizes.csv" –NoTypeInformation

CMD - Event 4292

Event Type: Error
Event Source: IPSEC
Event Category: None
Event ID: 4292
Date:
Time:
User: N/A
Computer: COMPUTER_NAME
Description:
The IPSec driver has entered Block mode. IPSec will discard all inbound and outbound TCP/IP network traffic that is not permitted by boot-time IPSec Policy exemptions.
Sometimes this solution http://support.microsoft.com/kb/912023 is working and I am also using this

net stop policyagent
regsvr32 polstore.dll
net start policyagent
+ reboot of server and it is working.

CMD - fix WMI

Commands to fix WMI:

%systemdrive%
cd %windir%\system32\wbem
net stop winmgmt /y
if exist repository.old rmdir /s /q repository.old
rename repository repository.old
net start winmgmt

CMD - uninstall windows update specific KB

To remove an update, use the command

wusa /uninstall /kb:2982791 /quiet 

and replace the KB number with the number of the update that you want to remove

VBS - write computer details to AD computer account description

original post, how to delegate permissions in AD
http://www.compit.se/?p=282


output:
martin.junge / SN: F4***R1 / Dell Latitude E6420 / Windows 8.1 Pro  x64 / Last Boot Time: 08.08.2014 / Last Update Time: 21.7.2014 / Bios vers.: A21 / bitlocker disabled


---my modified vbs file---

On Error Resume Next

strComputer = "."
Set objSysInfo = CreateObject( "WinNTSystemInfo" )
strUserName = objSysInfo.UserName


Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colcomputersystem = objWMIService.ExecQuery _
    ("Select * from Win32_computersystem")
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")

For each objcomputersystem in colcomputersystem
    Getcomputersystem = objcomputersystem.Model
    if Getcomputersystem = "VMware Virtual Platform" then Getcomputersystem = Right(Getcomputersystem, 17) end if

    if Getcomputersystem = "Virtual Machine" then
        Dim SysVarReg, Value
        Set SysVarReg = WScript.CreateObject("WScript.Shell")
        value = SysVarReg.RegRead ("HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\PhysicalHostName")
        Getcomputersystem = Getcomputersystem & " on " & value
    end if

    GetComputerManufacturer = objComputerSystem.Manufacturer
Next

'---get Manufacturer--------------------
   'String cleaning - Manufacturer includes only first word, and the serial removes any spaces.
txtCount = InStr(GetComputerManufacturer," ") - 1
GetComputerManufacturer = Left(GetComputerManufacturer,txtCount)
if GetComputerManufacturer = "Hewlett-Packard" then GetComputerManufacturer = "" end if
if GetComputerManufacturer = "TOSHIBA" then GetComputerManufacturer = "Toshiba" end if
if GetComputerManufacturer = "VMware," then GetComputerManufacturer = Left(GetComputerManufacturer, 6) end if

if GetComputerManufacturer = "LENOVO" then
    Dim objWMIService, colItems
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT Version FROM Win32_ComputerSystemProduct")
    For Each objItem in colItems
        Getcomputersystem = objItem.Version & " " & objItem.Name
    Next
    GetComputerManufacturer = "Lenovo"
end if

if GetComputerManufacturer = "Microsoft Virtual Machine" then
    VMHost = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\PhysicalHostName")
    GetComputerManufacturer = GetComputerManufacturer & "on " & VMHost
end if
'---end Manufacturer-------

'---get serialnumber and BIOS version----------
GetSerialNumber = Replace(GetSerialNumber, " ", "")
For each objBIOS in colBIOS
    GetSerialNumber = objBIOS.SerialNumber
    GetBiosVers = objBIOS.SMBIOSBIOSVersion
Next
if GetComputerManufacturer = "VMware" then GetSerialNumber = Left(GetSerialNumber, 6) end if

'---end serialnumber-------

'---get processor architecture type---
Dim WshShell
Dim OsType
Set WshShell = CreateObject("WScript.Shell")
OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
if OsType = "AMD64" then
OsType = "x64"
end if
'---end processor architecture type---

'---get Operating system---
Dim OSVersion
OSVersion = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
if OSVersion = "Microsoft Windows XP" then OSVersion = "Windows XP" end if
if OSVersion = "Microsoft Windows 2000" then OSVersion = "Windows 2000" end if
if OSVersion = "Microsoft Windows Server 2003" then OSVersion = "Windows Server 2003" end if
if OSVersion = "Microsoft Windows Server 2003 R2" then OSVersion = "Windows Server 2003 R2" end if
'---end Operating system---

'---get service pack version---
Const Impersonate = "winmgmts:{impersonationLevel=impersonate}!\\"
Set oWMI = GetObject(Impersonate & strComputer & "\root\cimv2")
Set QueryWMI = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each oItem In QueryWMI
spVer = oItem.ServicePackMajorVersion
if spVer = 0 then spVer ="" else spVer = "SP" & spVer end if
Next
'---end service pack version---

'---get last boot time start----
Dim strBoot, strBootDate, strBootDay, strBootHour, strBootMins
Dim strBootMonth, strBootTime, strBootYear, strMsg, strQuery
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_OperatingSystem", , 48 )
For Each objItem in colItems
strBootYear = Left( objItem.LastBootUpTime, 4 )
strBootMonth = Mid( objItem.LastBootUpTime, 5, 2 )
strBootDay = Mid( objItem.LastBootUpTime, 7, 2 )
strBootHour = Mid( objItem.LastBootUpTime, 9, 2 )
strBootMins = Mid( objItem.LastBootUpTime, 11, 2 )
strBootTime = strBootHour & ":" & strBootMins
Next
'---end last boot time----

'---get last windows update time------
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher
Set colHistory = objSearcher.QueryHistory(1, 1)
For Each objEntry in colHistory
 strHotfix = objEntry.Date
Next

'---end last windows update time------

'---get bitlocker status---

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume",,48)
For Each objItem in colItems
    bitlockerdiveletter = objItem.DriveLetter
    bitlockerstatus = objItem.ProtectionStatus
    if bitlockerdiveletter = "C:" then
        if bitlockerstatus=1 then bitlockerstatusnote = "bitlocker enabled" else bitlockerstatusnote = "bitlocker disabled" end if
    end if
next
'---end bitlocker status---

'---define AD description text for clients and servers
If InStr(OSVersion, "Server") Then
    strMessage = GetComputerManufacturer & " " & trim(Getcomputersystem) & " / " & "SN: " & trim(GetSerialNumber) & " / " & OSVersion & " " & spVer  & " " & OsType & " / " & "Last Boot Time: " & strBootDay & "." & strBootMonth & "." & strBootYear & " / Last Update Time: " &  day(strHotfix) & "." & month(strHotfix) & "." & year(strHotfix) & " / Bios vers.: " & GetBiosVers
else
    strMessage = strUserName & " / " & "SN: " & trim(GetSerialNumber) & " / " & GetComputerManufacturer & " " & trim(Getcomputersystem) & " / " & OSVersion & " " & spVer  & " " & OsType & " / " & "Last Boot Time: " & strBootDay & "." & strBootMonth & "." & strBootYear & " / Last Update Time: " &  day(strHotfix) & "." & month(strHotfix) & "." & year(strHotfix) & " / Bios vers.: " & GetBiosVers & " / " & bitlockerstatusnote
end if
'---end define---

'WScript.Echo strMessage   'for testing

objComputer.Description = strMessage
objComputer.SetInfo

'---eof---

CMD - stop / delete service on remoe machine in txt file

@echo off

set LISTFILE=clients.txt

for /f %%a in (%LISTFILE%) do (

    echo.
    echo --------------------------------
    echo.
    echo %%a
    ping -n 1 %%a | find "TTL="
        if not errorlevel 1 (
            echo.
                sc.exe \\%%a stop psexesvc
                sc.exe \\%%a delete psexesvc
            )
        if errorlevel 1 (
            echo %%a unavailable
            )
    )
pause

CMD - kill task on remote machines in txt file

@echo off

set LISTFILE=clients.txt

for /f %%a in (%LISTFILE%) do (

    echo.
    echo --------------------------------
    echo.
    echo. %%a
    ping -n 1 %%a | find "TTL="
        if not errorlevel 1 (
            TASKKILL /s %%a /IM iexplore.exe
            )
    )

pause