Archive for the 'Scripting' Category

Delete Files Remotely Using PowerShell Script

Keep Reading ...

To run this with out reading a list just remove the commands at the the bottom and replace the “$_” with computer name or replace the $file variable with local path
123456789101112131415#MAIN
function delete-remotefile {
    PROCESS {
                $file = "\\$_\c$\File_to_be_deleted.txt"
              [...]

AutoIT script to check if file exist then install application

Keep Reading ...

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596;==========================================================================
;
; NAME: outlook_addon.au3
;
; AUTHOR: John Sorensen
;
; COMMENT:
; Install an outlook 2003 specific addon using AutoIT.
;This will first check to see if the addon
; already exists and if not will check if outlook 2003
;exexcutable exest then will install showing a
; install showing progress. Edit the script as needed
;to include your own file and [...]

Run DOS command in VBscript

Keep Reading ...

DOS command can be run in Vb Script using the Shell object
The below script runs a mkdir command through Vb Script
Set objShell = CreateObject(“WScript.Shell”)
objShell.Run “%comspec% /c mkdir dir1″
If your in IT you know coffee is almost as important as the air we breath. Show your support and add to the coffee fund. SHOW YOUR SUPPORT… [...]

VBscript – Create Folders from Excel

Keep Reading ...

1234567891011121314151617181920212223242526272829303132′========================================================

‘ NAME: FolderFromExcel.vbs

‘ COMMENT:  Script will read Excel file.  Column A should contain
‘                  folder names. Folders will then be created.

‘========================================================
Dim objExcel, strPathExcel,strCN
Dim objFile, intRow

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")
strPathExcel = "c:\temp\excel.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

intRow = 1

Do Until objExcel.Cells(intRow, 1).Value = ""
    strCN = Trim(objSheet.Cells(intRow, [...]

Enumerate last user login times from Active Directory via powershell

Keep Reading ...

123456789101112131415161718192021222324# ==============================================================================================
#
# NAME: UserLastLogin.ps1
#
# AUTHOR: John Sorensen
#
# COMMENT: This script uses the DirectorySearcher object to search for all users in Active directory.
#      It then walks through the user accounts and determines the last logon date.
#      
#
# ==============================================================================================

$searcher = New-Object DirectoryServices.DirectorySearcher([adsi]"")
$searcher.filter = "(objectclass=user)"
$users = $searcher.findall()

Foreach($user [...]

VBScript – Enumerates all SamAccounts in you current Domain

Keep Reading ...

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112′==========================================================================
‘ NAME: List_AD_SamAccounts.vbs

‘ COMMENT: Enumerates all SamAccounts with department and descriptions

‘==========================================================================

Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes

Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName

Dim strDept, arrDescript, strDescript, strItem

‘ Setup ADO objects.

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

‘ Search entire Active [...]

Windows Installer Wrapper Wizard

Keep Reading ...

WIWW2 is a great tool to create custom MSI’s. I use this (and others) to primary setup MSI’s to deploy via script, GPO, WDM. Its a simple and no thrills wrapper but it does the trick.
This program is pretty much almost impossible to find now but here it is…
Windows Installer Wrapper Wizard (aka. WIWW2)
Download WWIW2

If [...]

Runs a script against multiple computers

Keep Reading ...

This snippet runs a script against multiple computers taken from a text file. A big time saver.
123456789101112131415161718192021′Create a FileSystemObject
Set oFS = CreateObject("Scripting.FileSystemObject")
‘Open a text file of computer names
‘with one computer name per line
Set oTS = oFS.OpenTextFile("c:computers.txt")

‘go through the text file
Do Until oTS.AtEndOfStream
‘get the next computer name
’store it in variable sComputer
sComputer = oTS.ReadLine

‘———————————–
‘ YOUR CODE HERE [...]

Query Scheduled Tasks using Powershell

Keep Reading ...

To use this powershell script place the script, the config file, and a list as a cvs file with the servers to be queried all in the same directory.
Save below as QueryScheduledTasks.ps1:
12345678910111213141516171819202122232425262728293031$Description="Generate CSV of scheduled tasks from a list of servers"

#——————————————————————————
# Settings / Variables
#——————————————————————————
If (Test-Path "QueryScheduledTasks.config") {
    $cfg=[xml](get-content "QueryScheduledTasks.config")
} Else {
    Write-Host "!! [...]

Script to check for new users or computers and email output

Keep Reading ...

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165′==========================================================================


‘ NAME: ADAddedUsersNComputers.vbs

‘ AUTHOR: John Sorensen
‘ DATE  : 2/2/2009

‘ This script Checks AD for any additions made to Users or Computers
‘ in the past 24 hours. The time interval to check can be changed below.

‘*****************************************************************************

‘Please modify these four settings
strSMTPServer = "your_mail_server.domain.com"
strEmailFrom = "Script Output  <script@domain.com>"
strEmailTo = "John Sorensen <you@domain.com>"

strTimeInUTC = CompareDateUTCConvert("h",-24) ‘This is the same [...]