9.28.2012

...goes a long way

...a little bit of script.

I'd been working twenty minutes in Excel when the copy I had 'went away'. I looked in task manager -- it was _there_ just couldn't see it. So, this brought it back:

EXAMPLE:

PS~MBEE1>type .\get-excel.vbs
Option Explicit
Dim oExcel
Set oExcel=GetObject(,"Excel.Application")
oExcel.Visible=vbTrue
PS~MBEE1>cscript //nologo //e:vbscript get-excel.vbs


Automation is _wonderful_.

9.05.2012

Example multi-thread ora client...

Not a _working_ example - but, at least a sample to follow in creating a multi-thread oracle client. It generates a number of simultaneous oraclient extracts -- then waits on completion before submitting more.

cmdlets involved: start-process,get-process,get-date

param([STRING]`
$psFROM='',`
$pnDAYS=1,`
$pnOracleCli=100,`
$pnINCR=-1) `
#Must be the first statement in your script
CLEAR-HOST
#   history:
#                   ~   $psFROM     date starting point 
#                   ~   $pnDAY      number to iterate[default 1] 
#                   ~   $pnINCR     whether back (-1) or forward (1)
#                   ~   $pnOraCli   number of clients to allow in tandem
$ldFROM   =(GET-DATE);$ldSTOP   =(GET-DATE);$ldTO     =(GET-DATE);
$lsFROM   =GET-DATE;$lsSTOP   =GET-DATE;$lsTO     =GET-DATE;

$lnDAYS      =0;$lnINCR      =$pnINCR;$lnOracleCli =$pnOracleCli;

if ($psFROM -ne $empty)
{$ldFROM  =GET-DATE   "$psFrom"   -FORMAT "dd-MMM-yyyy"}
else
{$ldFROM         =   GET-DATE}
$ldSTOP         =   (GET-DATE $ldFROM ).AddDays($pnDAYS*$pnINCR)
$ldTO           =   $ldFROM
$lsFROM         =   GET-DATE $ldFROM    -FORMAT "dd-MMM-yyyy"
$lsTO           =   GET-DATE $ldFROM    -FORMAT "dd-MMM-yyyy"
$lsSTOP         =   GET-DATE $ldSTOP    -FORMAT "dd-MMM-yyyy"
#at this point the dates s/b set now transform into
#how they're used in main part of script (in terms of format and type)
#start of loop
write-host "#-";
WRITE-HOST "# OraCli limit~$pnOracleCli~SO no daywidgets(16) X 5 DAYS = 90..."
$iDAYCOUNT=0;
while($ldFROM -ne $ldSTOP){
    WRITE-HOST "# Extracting Data For $lsFROM THRU $lsTO...stopping at $DATESTOP"
    START-PROCESS `
      -FILEPATH C:\ORANT\BIN\PLUS33.EXE `
      -WORKINGDIRECTORY m:\ `
      -WINDOWSTYLE MINIMIZED `
      -ARGUMENTLIST "$duserid/$dpassword@d @C:\yourQUERY.PDC Chunk1 $lsFROM $lsTO"
    START-PROCESS `
      -FILEPATH C:\ORANT\BIN\PLUS33.EXE `
      -WORKINGDIRECTORY m:\ `
      -WINDOWSTYLE MINIMIZED `
      -ARGUMENTLIST  "$duserid/$dpassword@d @C:\yourQUERY.PDC chunk2 $lsFROM $lsTO"
    START-PROCESS `
      -FILEPATH C:\ORANT\BIN\PLUS33.EXE `
      -WORKINGDIRECTORY m:\ `
      -WINDOWSTYLE MINIMIZED `
      -ARGUMENTLIST "$duserid/$dpassword@d @C:\yourQUERY.PDC chunk3 $lsFROM $lsTO"
...
    $iDAYCOUNT=$iDAYCOUNT+1;
    $ldFROM    =(get-date $lsFROM).adddays($lnINCR)
    $ldTO      =(get-date $lsTO).adddays($lnINCR)
    $lsFROM    =GET-DATE $ldFROM  -FORMAT "dd-MMM-yyyy"
    $lsTO      =GET-DATE $ldTO    -FORMAT "dd-MMM-yyyy"
    $iDAYCOUNT_MOD_5=$iDAYCOUNT % 5;
    if ($iDAYCOUNT_MOD_5 -eq 0){
        $iDAYCOUNT=0
        $I=0;
        $GPE=GET-PROCESS -NAME PLUS33 -ERRORACTION SILENTLYCONTINUE;
        FOREACH($P IN $GPE){
          IF($P.ID -NE $NULL){$I=$I+1}};
        $sqlplus_COUNT=$I;
        WRITE-HOST "#-"
        WRITE-HOST "# Spawn then wait for Oraclient(s) to finish..."
        WRITE-HOST "#-"
        $begin=GET-DATE
        WRITE-HOST "# $begin"
        while ($sqlplus_COUNT -ne 0){
            start-sleep -s 10
            $I=0;
            $GPE=GET-PROCESS `
              -NAME PLUS33 `
              -ERRORACTION SILENTLYCONTINUE;
            FOREACH($P IN $GPE){
                IF($P.ID -NE $NULL){
                    $I=$I+1
                }
            };
            $sqlplus_COUNT=$I;
        }
    }
}
write-host "#-"
write-host "# done..."
write-host "#-"
$done=get-date
write-host "# $d"

8.15.2012

8.14.2012

Signing

On a mission:

Find a straightforward method of signing ps scripts and implementing across enterprise desktops

What I've found so far are only examples of "self-signing" scripts.  I think what _I need_ is :

-a valid cert
-to authenticate with cert
-then accept cert (somehow...use .reg?) onto user desktop

Research:

-Google: http://bit.ly/mtbeeITProf_Script_GSearch_signing_powershell_scripts

Promising:

http://www.hanselman.com/blog/SigningPowerShellScripts.aspx

Requirements:

-Admin privilege
-.NET Framework 2.0 SDK
- Try: 3.5 Service Pack 1! ...but, you need role based install ~ security (harumph!)
  Note: Regarding error below - maybe due to them not running as
           comspec/makecert as ADMIN


-our admin are using a GPO to push the cert to desktops that require - only other
 gotcha encountered was that scripts created from the powershell ISE come out
'big endian' and generate 'unknownerror' when signing.  Resave as ANSI and that
problem goes away.

Caveat emptor:   ...at very bottom of article.

Thursday, August 10, 2006 10:42:27 PM UTCWhen running the "makecert" to add to the personal store teh following error occurs. Generally I don't set up my certs this way but wanted to use your blog as a reference for others. This seems to be a problem many are having on XPSP2 machines. I don't know if i happens on WS2000/3003.

Error: Can't load the issuer certificate ('root')
Failed

6.26.2012

Okay. PS is totally cool! Three line script to query remote eventlog:
 
PS C:\Documents and Settings\mbee>TYPE .\_PS1\QUERYSHEET_MSG_ERRORS.ps1
Clear-Host;
$Machine = "RIALTO";
Get-EventLog Application -newest 100|Where-Object { $_.Message -match "QUERYSH*"};
PS C:\Documents and Settings\mbee>.\_PS1\QUERYSHEET_MSG_ERRORS.ps1
Index Time        EntryType   Source  InstanceID Message
----- ----        ---------   ------  ---------- -------
3692 Jun 26 10:36 Information WSH     1073741828 QUERYSHEET_REFRESH.xlsm ~ 1004...

5.26.2012

I drag speak.vbs to Quick Launch menu, then high-light text in an app & launch.   Haven't tried in Windows7 ~ Vista; but, on XP will speak  the highlighted text using SAPI(microsoft Sam).

Download:

speak.vbs - https://www.box.com/s/1f1946821da027b114b0

Dim aaa_speak _
,   sClipboard _
,   oIE _
,   oSh _
,   oSAPI _
,   zzz_speak
Set oIE=CreateObject("InternetExplorer.Application")
Set oSAPI=CreateObject("SAPI.SpVoice")
Set oSh=CreateObject("WScript.Shell")
oSh.SendKeys "%{Tab}^{Insert}"
oIE.Navigate("about:blank")
sClipboard= _
  oIE.document.parentwindow.clipboardData.GetData("text")
oIE.Quit
oSAPI.Speak sClipBoard
Set oSh=Nothing
Set oSAPI=Nothing
WScript.Quit

5.02.2012

SQL Tidy

I've found a SQL Tidy program invaluable. I created a script for use with my favorite. If you download WANGZ.vbs to your desktop~other folder then create a couple of short-cuts you'll be in business...

Google 'SQL Tidy' ~ http://bit.ly/MTBeeITPr_Oracle_Google_SQL_Tidy

WANGZ.VBS
https://www.box.com/s/dfa05ecd928e6fc65a8d

WANGZ Oracle ~ short-cut
C:\WINDOWS\system32\cscript.exe /NOLOGO "WANGZ.VBS" /Database:MSAccess /Output:Text /Keywords:U /Identifier:N /Functions:U /Before:TRUE /Len:255

WANGZ MS-Access SQL ~ short-cut
C:\WINDOWS\system32\cscript.exe /NOLOGO "WANGZ.VBS" /Database:Oracle /Output:Text /Keywords:U /Identifier:N /Functions:U /Before:TRUE /Len:255

4.21.2012

1.27.2012

NPPCompare.VBS

'-
Dim aaaNPPCompare _
, oArgs _
, oFs _
, oSh _
, sDir2 _
, sMsg _
, zzzNPPCompare

Sub Help()
    sMsg = _
    " This uses Notepad++ to compare two files.  Assumptions:               " & vbLF & _
    " #1 Notepad++ is installed                                             " & vbLF & _
    " #2 'Compare' plug-in is active, e.g., if Plugins/Compare              " & vbLF & _
    "     doesn't show up -- activate by:                                   " & vbLF & _
    "     Plugins/Plugin Manager/Show Plugin Manager ... check 'Compare'.   "
    Msgbox sMsg,vbOkOnly,WScript.Scriptname
End Sub
'-
Sub QExit
    Set oSh=Nothing
    Set oFS=Nothing
    WScript.Quit
End Sub
'-

Set oSh=CreateObject("WScript.Shell")
Set oFS=CreateObject("Scripting.FileSystemObject")

If Not oFS.FileExists("C:\Program Files\Notepad++\notepad++.exe") Then
    Help
    QExit
End If
'-
Sub ccSleep(seconds)
  cmd = "%COMSPEC% /c ping -n " & _
    1 + seconds & " 127.0.0.1>nul"
  oSh.Run cmd,0,1
End Sub
'-
Set oArgs = WScript.Arguments
If oArgs.Count = 2 Then
  sDir2=Split(oArgs.Item(1),"\")
  oSh.Run _
    chr(34) & "c:\Program Files\" & _
              "Notepad++\" & _
              "notepad++.exe" & chr(34) & " " & _
      chr(34) & oArgs.Item(0) & chr(34) & _
        "," & _
      chr(34) & oArgs.Item(1) & chr(34)
    While Not _
      oSh.AppActivate(sDir2(UBound(sDir2)) & _
        " - Notepad++")
      ccSleep 1
    Wend
    oSh.AppActivate(sDir2(UBound(sDir2)) & _
      " - Notepad++")
    oSh.SendKeys "%P{Enter 2}"
End If

Set oSh=Nothing
Set oFS=Nothing

WScript.Quit

xlsx_to_vbs.VBS

Dim aaaXLSX_to_CSV _
, bDebug _
, oFS _
, oSh _
, sCSV _
, sDir _
, sFullName _
, sMsg _
, sXLSX _
, zzzXLSX_to_CSV
'-
Sub Help()
Dim vResult
sMsg = _
"Assumes:" & vbLF & _
"- an XLSX with a single tab" & vbLF & _
"- sheet expands to full window."
vResult=oSh.Popup _
(sMsg, _
7, _
WScript.ScriptName, _
vbYesNo+vbDefaultButton2)
If vResult<>vbYes Then
Set oSh=Nothing
Set oFS=Nothing
WScript.Quit
End If
End Sub
'-
Sub ccSleep(seconds)
cmd = "%COMSPEC% /c ping -n " & _
1 + seconds & " 127.0.0.1>nul"
oSh.Run cmd,0,1
End Sub
'-
Sub XLS_to_CSV(sFullName)
sDir=Split(sFullName, "\")
sXLSX=chr(34) & sFullName & chr(34)
If bDebug Then msgbox "sXLSX[" & sXLSX & "]"
sCSV= _
chr(34) & replace(sFullName,".xlsx",".csv") & chr(34)
If bDebug Then msgbox "sCSV[" & sCSV & "]"
oSh.Run "excel " & sXLSX
While Not _
oSh.AppActivate _
("Microsoft Excel - " & sDir(UBound(sDir)) )
ccSleep 1
Wend

oSh.AppActivate _
("Microsoft Excel - " & sDir(UBound(sDir)) )

On Error Resume Next
oFS.DeleteFile replace(sCSV,chr(34),"")

oSh.Sendkeys "%(FA){Tab}c{enter 3}"
While Not _
oSh.AppActivate _
("Microsoft Excel - " & _
Replace(sDir(UBound(sDir)),".xlsx",".csv") )
ccSleep 1
Wend

oSh.AppActivate _
("Microsoft Excel - " & _
Replace(sDir(UBound(sDir)),".xlsx",".csv") )
oSh.Sendkeys "%{F4}"
ccSleep 1
oSh.SendKeys "N"
End Sub
'-
' Main
'bDebug=vbTrue
Set oSh=CreateObject("WScript.Shell")
Set oFS=CreateObject("Scripting.FileSystemObject")
'
Help
'
For Each sFullName in WScript.Arguments
XLS_to_CSV sFullName
Next
'
Set oFS = Nothing
Set oSh = Nothing

WScript.Quit

1.21.2012

Created a 'SAY' command using AutoIt

Refreshing my Perl knowledge. Wanted to copy/paste examples and make them self-documenting (audio wise). Thought pre-pending text with 'SAY' and using this AutoIt script would work:

Dim $oSPV,$i,$msg,$speak_msg
$oSPV=ObjCreate("SAPI.spVoice")
For $i=1 to $cmdline[0]
$msg=$msg & ' ' & $cmdline[$i]
Next
$speak_msg=$msg
$speak_msg=stringreplace($speak_msg,'#',' ')
$speak_msg=stringreplace($speak_msg,'#',' ')
ConsoleWrite('REM ' & $msg & @lf)
$oSPV.Speak($speak_msg)

say.au3
say.exe

1.03.2012

myTTS/PROCQUIT - to speak selected text (in most any app)

Uses SAPI to play back highlighted text in an app.

Download myTTS.exe:
http://www.box.com/s/5xrya4nqu4cslzjlb000
 



If you wish to stop a long running ~ speaking text, download myPROCQUIT to same folder.
Press 'Escape' to quit the TTS applet.

Download myPROCQUIT:
http://www.box.com/s/kx2e576zmksltjspstnr