www.infralib.com

www.infralib.com
Please visit my new site http://www.infralib.com for my and other authors' newer posts, articles. We will also have forums, videos, webcasts and etc.
Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Thursday, 24 November 2011

Fixing Automatic update clients those not appear in WSUS console

It is very common issue that some Automatic Update clients don't show up in WSUS console or intermittently appears/disappears.

Main cause of the this problem is generally duplicate SUSClientID on clients having problems, and it is very easy to fix by renewing the value.

You can use a batch file like below to fix it easily. You should turn of echo and remove Pause commands if you will run this with GPO or other deployment tool like SMS/SCCM.

@echo on
Echo 1. Stopping the wuauserv service
net stop wuauserv
Pause
Echo 2. Deleting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\AccountDomainSid registry key (if it exists)
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v AccountDomainSid /f

Echo 3. Deleting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\PingID registry key (if it exists)
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v PingID /f

Echo 4. Deleting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\SusClientId registry key (if it exists)
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientId /f

Echo 5. Deleting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\SusClientIDValidation registry key (if it exists)
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientIDValidation /f

Echo 5. Restarting the wuauserv service
net start wuauserv
Pause

Echo 6. Resetting the Authorization Cookie (Wait 10 minutes for a detection cycle to finish)
wuauclt /resetauthorization /detectnow
Pause

Friday, 11 November 2011

Create Desktop Shortcut with Script

Hi all

Today, I have received an application to deploy with SMS Server 2003, I had to create a MSI Package and some scripts to make that application installation most user friendly, actualy without need to user interaction. So I have needed a script that can find logged user profile folder and create a desktop shortcut to the configuration file in user profile folder.

I have found an article about how to create desktop shortcuts at Technet http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_aytf.mspx?mfr=true , it is detailed enough to understand how to do it,

Technet Script :

Set objShell = WScript.CreateObject("WScript.Shell")
strDesktopFolder = objShell.SpecialFolders("AllUsersDesktop")
Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\IIS Manager.lnk")
objShortCut.TargetPath = "%SystemRoot%\System32\Inetsrv\iis.msc"
objShortCut.Save


As you see above script creates WshShortcut object by calling CreateOBject, than it defines Desktop folder path with strDesktopFolder by AllUsersDesktop value. But we will change this script to locate and crete a desktop shortcut of a file that unique for every user.

First of all we need to find logged users profile path, to do this we will get USERSPROFILE value from Windows Environment Settings by adding this line

UsersProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

now we know logged users profile path has defined in UsersProfile (e.g. C:\Documents and Settings\OShener)

*Tip : You can get another Windows Environment variables values by using objShell.ExpandEnvironmentStrings by changing variable name in (%%) , you can check your existing environment variables by running set command in command promt too.

So where is our user specific target file for shortcut ? Let assume it is located in DW folder and the DW folder is in the the logged users profile folder. Now we are going to define a variable to fix the target file path with this line:

objShortCut.TargetPath = UsersProfile & "\DW\DW.conf"

and to find and define logged users desktop path to a variable we add this line to the script too

strDesktopFolder = objShell.SpecialFolders("Desktop")

and we have to define the Desktop Shortcut location before create it

Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\DWConf.lnk")


Ok, let tidy up the script and see what we have now ?

Set objShell = WScript.CreateObject("WScript.Shell")
UsersProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strDesktopFolder = objShell.SpecialFolders("Desktop")
Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\DWConf.lnk")
objShortCut.TargetPath = UsersProfile & "\DW\DW.conf"
objShortCut.Save


If you wish you can add different properties to your shortcut too, like Windows HotKey, Description, Working Folder, only thing you need to do that add ObjShortcut properties as : objShortCut.HotKey = "Ctrl+Shift+D" and refer to the link : http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_aytf.mspx?mfr=true

Regards

Osman Shener 19th-09-2007

Saturday, 5 March 2011

Create list of all WDS devices with a vbscript

I am trying to write a script/web based console to manage WDS (Windows Deployment Server) Approved, Pending and Rejected devices more user friendly. And I'd like to share first part of it, actually it is just preparation phase, but I thought it may give ideas.
The script exports all devices to text files by using wdsutil then parse the text files to create more usable semi column seperated files. PS: It is my draft version.



Example
When we run wdsutil /get-AutoAddDevices /DeviceType:RejectedDevices command and export the result to a text file it produces the format below.



The script parses and re-writes the text file and make it more usable like below.


Script : ListWDSAll Devices.vbs
Author : Osman Shener
'ListWDSAllDevices.vbs Written by : Osman Shener
'Feel free to use! (Kill the hero, but don't eat his right :) (Don't try to undertand it is a funny translation of a Turkish proverb))

Const ForReading = 1
Const ForWriting = 2
Const TristateUseDefault=-2

Dim objFSO, arrStr, wshell, objRegEx

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshell = CreateObject("WScript.Shell")
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "\:"

wshell.run "%COMSPEC% /C wdsutil /get-AutoAddDevices /DeviceType:PendingDevices > C:\PendingDevices.txt", 0, TRUE
wshell.run "%COMSPEC% /C wdsutil /get-AutoAddDevices /DeviceType:RejectedDevices > C:\RejectedDevices.txt", 0, TRUE
wshell.run "%COMSPEC% /C wdsutil /get-AutoAddDevices /DeviceType:ApprovedDevices > C:\ApprovedDevices.txt", 0, TRUE
set wshell = nothing


'Create Pending Devices Semicolon seperated list!
Set objFile = objFSO.OpenTextFile("C:\PendingDevices.txt", ForReading, True, TristateUseDefault)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set colMatches = objRegEx.Execute(strLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strPenText = strPenText + strLine + ";"
If Left(strLine, 11) = "Join domain" Then
strPenText = strPenText & vbCrLf
End If

' Wscript.Echo strPenText
Next
End If
Loop
objFile.Close

Set objFile = objFSO.OpenTextFile ("C:\PendingDevicesList.txt", ForWriting, True, TristateUseDefault)
objFile.Write(strPenText)
objFile.Close


'Create Approved Devices Semicolon seperated list!
Set objFile = objFSO.OpenTextFile("C:\ApprovedDevices.txt", ForReading, True, TristateUseDefault)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set colMatches = objRegEx.Execute(strLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strAppText = strAppText + strLine + ";"
If Left(strLine, 13) = "Approval time" Then
strAppText = strAppText & vbCrLf
End If

' Wscript.Echo strAppText
Next
End If
Loop
objFile.Close

Set objFile = objFSO.OpenTextFile ("C:\ApprovedDevicesList.txt", ForWriting, True, TristateUseDefault)
objFile.Write(strAppText)
objFile.Close


'Create Rejected Devices Semicolon seperated list!
Set objFile = objFSO.OpenTextFile("C:\RejectedDevices.txt", ForReading, True, TristateUseDefault)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set colMatches = objRegEx.Execute(strLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strRejText = strRejText + strLine + ";"
If Left(strLine, 14) = "Rejection time" Then
strRejText = strRejText & vbCrLf
End If
Next
End If
Loop
objFile.Close

Set objFile = objFSO.OpenTextFile ("C:\RejectedDevicesList.txt", ForWriting, True, TristateUseDefault)
objFile.Write(strRejText)
objFile.Close