Labels

Friday, May 30, 2008

Poke-Info PowerShell script

I was working next to someone the other day, and there were two monitors connected to each PC, and he had just dragged a script from his right monitor to the left to read. It occurred to me that it would be handy to have a grid-connected view of desktops/monitors, and you could essentially drag and drop windows between computers.

Needless to say this probably isn't going to be achievable in 10 lines of powershell script, but as a version 0.01 of the concept, this script will take a file and a computer as parameters, and copy the file remotely and start notepad on the interactive desktop of the remote machine.



param (
$file = "",
$computer = ""
)


#
# 30/05/2008, Wayne Martin, Initial version
#
# Description:
# Poke a file into a notepad.exe process in the interactive desktop on a remote machine.
#
# Assumptions, this script works on the assumption that:
# psexec.exe is available on the host
# the account running the powershell script has administrative access to the remote computer
# WMI is accessible on the remote machine (queries remote temp directory and windir)
#
# Usage
# Copy a text file to a remote machine and start notepad on the interactive desktop
# . .\PokeInfo.ps1 -f textfile.txt -m RemoteMachine1
#
# Notes
# psexec.exe is required on the host
# This could also be achieved by using win32_Schedulejob interactive now+1, but this assumes schedule is running on the remote machine and time is synchronised
#
# References:
# http://blogs.msdn.com/powershell/archive/2007/01/16/managing-processes-in-powershell.aspx
#

write-output ("Copying and remotely loading " + $file + " on " + $computer)
$envTemp = (get-WMIObject -computerName $computer -class win32_environment -property VariableValue -filter "Name='Temp' AND SystemVariable=True").VariableValue
$windir = (get-WMIObject -computerName $computer -class win32_operatingsystem -property WindowsDirectory).WindowsDirectory

$tempfile = [System.IO.Path]::GetRandomFileName()
$localDest = $envTemp.Replace("%SystemRoot%", $windir) + "\" + $tempfile
$UNCDest = "\\" + $computer + "\" + $localDest.Replace(":", "$")

copy-item -path $file -dest $UNCdest

$cmd = "\\" + $computer + " /i /d notepad " + $localdest
write-output ("Running " + $cmd)
[diagnostics.process]::start("psexec.exe", "$cmd")



Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Reading web content with PowerShell

The following PowerShell code shows 6 different methods of using the .Net framework to read HTML/ASP responses, useful for scraping web pages through script. If you don't have a proxy server, just comment out the $wc.proxy lines.

$user = $env:username
$webproxy = "http://proxy:8080"
$pwd = Read-Host "Password?" -assecurestring

$proxy = new-object System.Net.WebProxy
$proxy.Address = $webproxy
$account = new-object System.Net.NetworkCredential($user,[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)), "")
$proxy.credentials = $account


# -- Method 1 - DownloadData -- #

$url = "http://www.sitemeter.com/?a=stats&s=s451qaz2WSX&r=0"
$wc = new-object system.net.WebClient
$wc.proxy = $proxy
$webpage = $wc.DownloadData($url)
$string = [System.Text.Encoding]::ASCII.GetString($webpage)

# -- Method 2 - DownloadData (QueryString) -- #

$url = "http://www.sitemeter.com"
$col = new-object System.Collections.Specialized.NameValueCollection
$col.Add("a","stats")
$col.Add("s","s451qaz2WSX")

$wc = new-object system.net.WebClient
$wc.proxy = $proxy
$wc.QueryString = $col
$webpage = $wc.DownloadData($url)
$string = [System.Text.Encoding]::ASCII.GetString($webpage)

# -- Method 3 - UploadData (POST) -- #

$url = "http://www.sitemeter.com"
$wc = new-object system.net.WebClient
$postData = "a=stats&s=s451qaz2wsx"
$wc.Headers.Add("Content-Type","application/x-www-form-urlencoded")
$wc.proxy = $proxy
[byte[]]$byteArray = [System.Text.Encoding]::ASCII.GetBytes($postData)
$webpage = $wc.UploadData($url,"POST",$byteArray);
$string = [System.Text.Encoding]::ASCII.GetString($webpage)

# -- Method 4 - GetResponse Stream -- #

$url = "http://www.sitemeter.com/?a=stats&s=s451qaz2wsx"
$wr = [System.Net.WebRequest]::Create($url)
$wr.Proxy = $proxy
$wresponse=$wr.GetResponse()

$requestStream = $wresponse.GetResponseStream()
$readStream = new-object System.IO.StreamReader $requestStream
$wrs = $readStream.ReadToEnd()
$readStream.Close()
$wresponse.Close()

# -- Method 5 - UploadValues -- #

$url = "http://www.sitemeter.com/default.asp"
$wc = new-object system.net.WebClient
$wc.proxy = $proxy
$col = new-object System.Collections.Specialized.NameValueCollection
$col.Add("a","stats")
$col.Add("s","s451qaz2WSX")
$wc.QueryString = $col
$webpage = $wc.UploadValues($url, "POST", $col)
$string = [System.Text.Encoding]::ASCII.GetString($webpage)

# -- Method 6 - UploadString - this doesn't seem to post properly -- #

$url = "http://www.sitemeter.com/default.asp"
$wc = new-object system.net.WebClient
$wc.proxy = $proxy
$postData = "/?a=stats&s=s451qaz2wsx"
$webpage = $wc.UploadString($url, $postData)
$webpage



Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Sunday, May 25, 2008

Automated Cluster File Security and Purging

If you have a cluster share that contains temporary data in separate top-level directories, this post may help you automate the security and purging of that shared data. This is useful for transient data such as drop directories for scanners and faxes, or scratch directories for general sharing.

To summarise, this will provide:

  1. A cluster-based scheduled task that runs each day, dependant on the network name and physical disk resource currently hosting the directory
  2. A batch file run by the scheduled task that secures each directory, and purges files older than 30 days, logging results to the physical node hosting the resource.

Creating the Scheduled Task

  1. Create the scheduled task cluster resource:
    cluster /cluster:%cluster% res "%resource_name%" /create /group:"%cluster_group%" /type:"Volume Shadow Copy Service Task"
    cluster /cluster:%cluster% res "%resource_name%" /priv ApplicationName="cmd.exe"
    cluster /cluster:%cluster% res "%resource_name%" /priv ApplicationParams="/c c:\admin\SecureAndPurge.bat"
    cluster /cluster:%cluster% res "%resource_name%" /priv CurrentDirectory=""
    cluster /cluster:%cluster% res "%resource_name%" /prop Description="%resource_name%"
    cluster /cluster:%cluster% res "%resource_name%" /AddDep:"%network_name_resource%"
    cluster /cluster:%cluster% res "%resource_name%" /AddDep:"%disk_resource%"
    cluster /cluster:%cluster% res "%resource_name%" /On
    cluster /cluster:%cluster% res "%resource_name%" /prop RestartAction=1
  2. Set the schedule for the cluster resource:
    • Use the cluster administrator GUI, this cannot currently be set with cluster.exe with the VSS scheduled task cluster resource
  3. Restart the resource to pickup the schedule change:
    cluster /cluster:%cluster% res "%resource_name%" /Off
    cluster /cluster:%cluster% res "%resource_name%" /On

Note that the cluster resource providing scheduled task capability is the ‘Volume Shadow Copy Service Task’ resource. This is a recommended solution from Microsoft for providing scheduled task capability on a cluster. See the ‘Cluster Resource’ document in the references below.

The LooksAlive and IsAlive functions for the VSSTask.dll simply check that the scheduled task is known to the local task scheduler. To further reduce the impact of resource failure, the resource should be marked as not affecting the cluster, preventing potential failover if this task were to fail more than three times (by default).

The scheduled task should run a simple batch file on the local disk of the cluster node. Keeping the batch file local further reduces the risk that problems with the batch file could cause the cluster group to fail. The theory is that if the batch file is on local disk, it can be modified/deleted before bringing the cluster resources online.

Creating the batch file

Create a batch file and set some environment variables for %directory%, %purgeDir%, %domain%, %logFile%, %AdminUtil%, %FileAge% to fit your environment, and then include at least the three commands below:

  • Set the security on each directory within the directory. Note that this assumes that for each directory, there is a matching same-named security group, prefixed with l (for local), eg lDirectory1.

    for /d %%i in (%Directory%\*) do cacls %%i /e /g %Domain%\l%%~ni:C >> %LogFile%
  • Move the files with robocopy that are older than %FileAge% days:

    %AdminUtil%\robocopy %Directory% "%PurgeDir%" *.* /minage:%FileAge% /v /fp /ts /mov /e /r:1 /w:1 /log+:%LogFile%
  • Delete the files that were moved:

    If Exist "%PurgeDir%" rd /s /q "%PurgeDir%"

Note that depending on the size of data, you might want to ensure that the purgedir is on the same volume as the source files, which won't use any disk space as the files are moved. If the purgedir was on a different drive you would temporarily need as much free space as the size of data being purged.

References:

Cluster resource
http://technet2.microsoft.com/windowsserver/en/library/f6b35982-b355-4b55-8d7f-33127ded5d371033.mspx?mfr=true

Volume Shadow Copy Service resource type
http://technet2.microsoft.com/windowsserver/en/library/bc7b7f3a-d477-42b8-8f2d-a99748e3db3b1033.mspx?mfr=true

Using Shadow Copies of Shared Folders in a server cluster
http://technet2.microsoft.com/windowsserver/en/library/66a9936d-2234-411f-87b4-9699d5401c8c1033.mspx?mfr=true

Scheduled task does not run after you push the task to another computer
http://support.microsoft.com/kb/317529

Scheduled Task for the Shadow Copies of Shared Folders Feature May Not Run on a Windows Server 2003 Cluster
http://support.microsoft.com/kb/828259

Behavior of the LooksAlive and IsAlive functions for the resources that are included in the Windows Server Clustering component of Windows Server 2003
http://support.microsoft.com/kb/914458

Generic Cluster-enabled Scheduled Tasks:
http://waynes-world-it.blogspot.com/2008/04/2003-cluster-enabled-scheduled-tasks.html



Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Friday, May 23, 2008

Managing printers at the command-line

This post provides a method of using the command-line to add printer drivers to a Windows 2003 print server, and then create and configure the port and printer. You can use this to create a control file with your printers, and then run these commands against the control file. There are also a few commands to gather information from your printer server(s) from the directory and event log.

Adding a driver

The printuientry calls have slightly different syntax between XP and 2003, hence the OS specific commands below even though the same print server is being targeted:

The Driver model name should be extracted from the INF and replace the example HP UPD driver.

On XP against a 32-bit print server:
rundll32 printui.dll,PrintUIEntry /ia /c\\printserver /m "HP Universal Printing PCL 6" /h "Intel" /v "Windows 2000 or XP" /f \\server\drivers\hpupd_pcl6_x86\hpu4pdpc.inf

On a 2003 x64 server, serving x86 clients (therefore both drivers are required):
rundll32 printui.dll,PrintUIEntry /ia /c \\printserver /m "HP Universal Printing PCL 6" /h "x64" /v "Windows XP and Windows Server 2003" /f file://server/drivers/hpupd_pcl6_x64/hpu4pdpc.inf

rundll32 printui.dll,PrintUIEntry /ia /c \\printserver /m "HP Universal Printing PCL 6" /h "x86" /v "Windows 2000, Windows XP and Windows Server 2003" /f \\server\drivers\hpupd_pcl6_x86\hpu4pdpc.inf

Creating ports/printers

Create a control file containing:
<PRINTER_NAME>,<PRINTER_IP>,<PRINTER_DRIVER>,<PRINTER_LOCATION>

For example:
Printer1,192.168.0.10,HP Universal Printing PCL 6,Printer/Location/1

Ping the IP Address for the printer:
for /f "tokens=1-4 delims=," %i in (controlfile) do @echo. &@echo %i,%j,%k,%l &@ping -n 1 %j

Register the prnadmin.dll if not already done:
cd /d "C:\Program Files\Windows Resource Kits\Tools" && regsvr32 /s prnadmin.dll

Assuming the driver is already installed, Add a DNS record create the port, Use the Microsoft Windows Resource Kit Tools to create the port and printer, configure the share and publish to AD, set duplex defaults, grant permissions to manage printers to a security group and ensure the print processor is winprint

for /f "tokens=1-4 delims=," %i in (controlfile) do @echo dnscmd %ad_dns_server% /recordadd %domain% %i A %j

for /f "tokens=1-4 delims=," %i in (controlfile) do @cscript portmgr.vbs -a -c \\printserver -p %i -h %j -t LPR -q %i

for /f "tokens=1-4 delims=," %i in (controlfile) do @cscript prnmgr.vbs -a -c \\printserver -b %i -m "%k" -r %i

for /f "tokens=1-4 delims=," %i in (controlfile) do @cscript prncfg.vbs -s -b \\printserver\%i -h %i -l "%l" +published

for /f "tokens=1-4 delims=," %i in (controlfile) do @setprinter \\printserver\%i 8 "pDevMode=dmDuplex=2,dmCollate=1,dmFields=duplex collate"

for /f "tokens=1-4 delims=," %i in (controlfile) do @c:\util\subinacl /printer \\printserver\%i /grant=domain\group=M

for /f "tokens=1-4 delims=," %i in (controlfile) do @setprinter \\printserver\%i 2 pPrintProcessor="WinPrint"

Print a test page to each printer:
for /f "tokens=1-4 delims=," %i in (controlfile) do cscript prnctrl.vbs -t -b \\printserver\%i

Check the printer is published in AD:
for /f "tokens=1-4 delims=," %i in (controlfile) do dsquery * CN=printserver,OU=ServerOU,DC=domain,DC=com -filter "(&(printShareName=%i))"

Note that subinacl.exe in the rktools isn't very functional, 5.2.3790.1180 is much better:
http://www.microsoft.com/downloads/details.aspx?FamilyID=E8BA3E56-D8FE-4A91-93CF-ED6985E3927B

Gathering information from a print server

Export Print Server details:
dsquery * OU=ServerOU,DC=domain,DC=com -limit 0 -filter "(&(objectClass=printQueue)(objectCategory=printQueue))" -attr cn printerName driverName printCollate printColor printLanguage printSpooling driverVersion printStaplingSupported printMemory printRate printRateUnit printMediaReady

csvde -f PrinterDetails.csv -d OU=ServerOU,DC=domain,DC=com -r "(&(objectClass=printQueue)(objectCategory=printQueue))" -l cn,printerName,location,driverName,printCollate,printColor,printLanguage,printSpooling,driverVersion,printStaplingSupported,printMemory,printRate,printRateUnit,printMediaReady
Dump event logs for the last day:
c:\util\dumpel -s \\printserver -l System -e 10 -m Print -d 1

Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

File System Filters and minifilters

File system filters with the filter manager and minifilters are often overlooked, until a clash occurs when you've got several different products using these filters, such as anti-virus, file screening, offline archiving, quotas etc.

This post provides information on a few utilities I've used to identify the file system filters currently installed, and how you can then start diagnosing issues with the verifier.exe driver verification tool.

The commands below show the file system filters installed, their current altitude, and which volumes they’re attached to:

C:\>Fltmc.exe

Filter Name Num Instances Frame
------------------------------ ------------- -----
SAVOnAccessFilter
DfsDriver
Datascrn 0 0
FileScreenFilter 3 0
EvFilter 3 0
Quota 0 0

C:\>Fltmc.exe instances
Filter Volume Name Altitude Instance Name
----------------------------- ----------------------------- ---------------- --------------------
FileScreenFilter C: 260800 FileScreenFilter
FileScreenFilter D: 260800 FileScreenFilter
EvFilter C: 185100 EvFilter
EvFilter D: 185100 EvFilter

Debugging tools for Windows also has some file system driver diagnostics:

  • Install the debugging tools for windows (windbg)
  • Load windbg
  • Debug the kernel, using local connection
  • Load the filter kernel debugging extensions - .load fltkd
  • Use !fltkd.help, or specific commands from the articles below (!filters !volumes etc)

Once you have worked out which drivers are the file system filters and minifilters, you can then run verifier.exe on the machine to monitor the drivers. This enables you to record statistics such as memory paging and interrupts. Any number of the currently installed drivers can be monitored

How NTFS Works

Filter Manager and Minifilter Driver Architecture



Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

OpsMgr 2007 SSRS Reports using SQL 2005 XML

This post relates mostly to the concept of passing XML between SQL Server Reporting Services (SSRS), Operations Manager Smart Controls, and SQL Stored Procedures when you are customising Operations Manager 2007 reporting.

Passing multi-valued parameters from the Operations Manager Smart Controls through the SSRS report to SQL can be difficult, and the method employed most by the default Microsoft reports seems to be XML.

SQL 2005 includes the XML data type and associated methods, including XQuery, a subset of the XPath query standard. In addition, SQL supports OPENXML – a rowset provider to construct a relational rowset view of an XML document.

Included below are two examples of processing an XML string and querying an element value from the XML elements with a SQL insert/select clause.

declare @execerror int
declare @xmldoc xml
declare @ixmldoc int
set @xmldoc = '<Data><Objects><Object Use="Containment">376</Object><Object Use="Containment">300</Object></Objects></Data>'
DECLARE @tblTest table (test int)


/* Parse the XML document and insert the converted int <object> element value into a temporary table */

EXEC @ExecError = sp_xml_preparedocument @ixmldoc OUTPUT, @xmldoc
INSERT INTO @tblTest
SELECT * FROM
OPENXML (@ixmldoc, '/Data/Objects/Object')
WITH (InstanceFilter int '.')

select * from @tbltest


/* Translate the value of <object> nodes to an int from an XML document into the test field of the table */

INSERT INTO @tblTest (test)
select tblTest.test.value('.', 'int')
from @xmldoc.nodes('/Data/Objects/Object') AS tblTest(test)

select * from @tbltest


Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Tuesday, May 20, 2008

Access Based Enumeration in 2003 and MSCS

This post provides an overview of Access Based Enumeration on Windows Server 2003, some limitations, advantages and information on controlling ABE in an Windows MSCS environment.

With a standard Windows file server, for users to map the share and view the directories they have access to, all users require the list directory right at the root of the share. The client would then see all directories, and receive access denied errors if they try to navigate to any sub-folder without NTFS access.

To provide access control similar to Netware, Microsoft have introduced Access Based Enumeration in Windows Server 2003 SP1. This provides a method of displaying only files and folders that a user has access to, rather than displaying all objects in the tree.

The best description I can give is that ABE will hide what you don't have access to, as opposed to ensuring you can see what you do have access to. For example, if you have .\A .\A\B and .\A\B\C, and you have access to C but you don't have access to B, C will be hidden through the explorer GUI.

While this allows for a seamless migration from Netware-based file servers, there are several potential limitations:

  • ABE has to be installed as a separate component to the Operating System, which must be documented and managed for implementation and recovery scenarios.
  • ABE is not cluster-aware, and as enabling ABE is a per-share operation, cluster failovers resulting in the dynamic creation of shares on a physical cluster node will not create ABE-enabled shares. A generic cluster application could be created to enable ABE on all shares as they are created on each cluster node. This is non-standard and not ideal.
  • Increased CPU usage on the file server and slower response times to the client, processing the file data to provide information to the client on which files and directories are visible. Depending on the algorithm used, the size and depth of data structures and file system security, this may be an issue.
  • There are known issues with DFS and Access Based Enumeration
  • There are known issues with the cache on multi-user workstations, which will provide a view of any files and directories that have been viewed by any user of a computer. Client cache characteristics such as retention and location are not known.

Advantages:

  • If looking at migrating from Netware to Microsoft file sharing, the migration will be seamless for users. The file/directory structure and security will be similar, along with end-user access.
  • Using ABE is a documented solution for managing the sharing and access control for clustered home folders, rather than using the share sub-directories feature of MSCS.

Notes:

  • There are known issues with backup applications that do not use the ‘back up files and directories’ right backing up data through standard file shares.
  • It is unknown whether navigating with explorer to a top-level directory causes server-side processing of all files/folders in the share to determine the access path to all items in the tree, or whether the algorithm will process per-directory. This may be relevant in determining the test-cases to apply to assess performance. Based on testing, it is assumed that if access is denied at a top-level, sub-folders and files are not processed deeper in that branch.
  • Windows Server 2008 includes cluster-aware ABE, enabled by default on all shares. Going forward this minimises the risk that this is a non-standard solution.

Controlling ABE in a cluster environment

Access Based Enumeration is controlled through SMB share settings for each instance of the lanmanserver service – each physical node in the cluster. These settings are not cluster-aware, and will be lost during a cluster fail-over operation.

To ensure that ABE follows virtual cluster nodes during failovers, a generic cluster application can be created, running the abecmd.exe to verify that ABE is enabled after failover. The cluster application will be dependant on the file share resource, run for each file share.

Resource Type - Generic Cluster Application
Resource Name - <share> ABE
Description - <share> ABE
Dependencies - <share>
Command - cmd.exe /k abecmd.exe /enable <share>
Current Directory - %SystemRoot%
Interact with Desktop - De-selected

Notes:

  1. This assumes abecmd.exe is available in the path of each physical cluster node (this is the case when you install the Microsoft package).
  2. The /k switch is required to ensure that the cmd.exe application remains open, after the abecmd.exe process terminates. This ensures that the cluster resource monitor does not detect the resource as failed. This also leaves a command shell running for each instance of ABE being enabled, certainly not ideal and potentially misleading.

Other solutions considered

Other solutions I've considered for controlling ABE in a Windows file and print cluster environment included:

  1. Creating a generic cluster application dependent on all shares within a particular group, using the 'abecmd.exe /all' method. This is potentially less maintenance, but does not offer granular control of particular shares
  2. Creating a generic script resource type, with a VBScript using the supported cluster entry points to enable ABE on shares when they are created. This requires VBScript knowledge to create and maintain the solution, as opposed to a standard Microsoft provided executable.
  3. Creating an external watcher than determine cluster failovers and share re-creation, running the appropriate abecmd.exe commands as required. This requires an external server process, either a compiled application or script, watching the cluster, not intuitive and adding a single point of failure
  4. Controlling Access Based Enumeration through Group Policy. Third-party software exists to control the enforcement of Access Based Enumeration to file servers. However, unless the scheduled GPO refresh period was very regular, this would not be relevant in a failover cluster scenario.

CPU usage and end-user response times

The biggest concern is response times, as the Microsoft whitepaper on ABE determines that with 150,000 files, the operation of ‘reading shared directories’ increase from 12 seconds to up to 58 seconds. However, there is no detail on the type of test performed or the hardware used.

On a 2003 cluster with several million files and more than a terabyte of data, no performance impacts have been noticed when accessing folder structures through shares with ABE enabled.

References:

Access Mask:
http://msdn2.microsoft.com/en-us/library/ms790780.aspx

Access Based Enumeration whitepaper:
http://www.microsoft.com/windowsserver2003/techinfo/overview/abe.mspx

Access Based Enumeration:
http://technet2.microsoft.com/WindowsServer/en/library/f04862a9-3e37-4f8c-ba87-917f4fb5b42c1033.mspx

Enabling ABE with DFS:
http://support.microsoft.com/kb/907458

Implementing home folders on a cluster server:
http://support.microsoft.com/kb/256926

Windows Server 2008 failover clustering:
http://technet2.microsoft.com/windowsserver2008/en/library/13c0a922-6097-4f34-ac64-18820094128b1033.mspx?mfr=true

Scripting Entry Points:
http://msdn2.microsoft.com/en-us/library/aa372846.aspx

Create a generic application resource type:
http://technet2.microsoft.com/windowsserver/en/library/ad0bd83d-6144-45b5-8dda-3e599d1edfdb1033.mspx

Generic script cluster resource:
http://www.microsoft.com/windowsserver2003/technologies/clustering/resources.mspx
http://msdn2.microsoft.com/en-us/library/aa369599.aspx
http://msdn2.microsoft.com/en-us/library/aa373089.aspx





Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Friday, May 16, 2008

Find VM snapshots in ESX/VC

Below are four methods I have used to find snapshots of VMs in ESX and VirtualCenter, other than manually looking through each VM in the GUI. Query the database using SQL management studio, use sqlcmd from the command-line, list the files in the service console, or use the new VI Toolkit powershell snap-in.

  1. Query SQL using SQL Server Management Studio

    select ENT.Name as 'Name', Lower(DNS_Name) as 'DNS Name', Guest_OS as 'OS', Mem_Size_MB as 'Mem', IP_Address as 'IP', VM.FILE_Name as 'VMX location', VM.Suspend_Time as 'Suspend Time', VM.Suspend_Interval as 'Suspend Interval', VMS.Snapshot_Name as 'Snapshot Name', VMS.Snapshot_Desc 'Snapshot Description', DateAdd(Hour, 10, VMS.Create_Time) as 'Snapshot Time', VMS.Is_Current_Snapshot 'Current Snapshot' from vpx_vm VM inner join VPX_GUEST_NET_ADAPTER NET on VM.ID = NET.VM_ID inner join VPX_ENTITY ENT on VM.ID = ENT.ID inner join VPX_SNAPSHOT VMS on VM.ID = VMS.VM_ID

  2. Use sqlcmd.exe to run the query

    Run this query from a command-line after updating the server and database parameters:
    sqlcmd -S %server% -d %database% -W -s "," -Q "select ENT.Name as 'Name', Lower(DNS_Name) as 'DNS Name', Guest_OS as 'OS', Mem_Size_MB as 'Mem', IP_Address as 'IP', VM.FILE_Name as 'VMX location', VM.Suspend_Time as 'Suspend Time', VM.Suspend_Interval as 'Suspend Interval', VMS.Snapshot_Name as 'Snapshot Name', VMS.Snapshot_Desc 'Snapshot Description', DateAdd(Hour, 10, VMS.Create_Time) as 'Snapshot Time', VMS.Is_Current_Snapshot 'Current Snapshot' from vpx_vm VM inner join VPX_GUEST_NET_ADAPTER NET on VM.ID = NET.VM_ID inner join VPX_ENTITY ENT on VM.ID = ENT.ID inner join VPX_SNAPSHOT VMS on VM.ID = VMS.VM_ID"

  3. Connect to the service console and query for the files in the VMFS volumes

    ls -Ral /vmfs/volumes/* grep .vmsn

  4. Use the VI Toolkit to connect to a VC instance and query for snapshots. Note that this is currently in beta, so for write operations in production I suggest waiting for the production release of the toolkit.
  • Install VMware-Vim4PS-e.x.p-81531.exe (or later)
  • Run this command (or use the start menu shortcut) C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command ". \"C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\init.ps1\"" \
  • Get-VC -server %vc-server% (you will be prompted for credentials unless you have a valid certificate path)
  • Get-VM Get-Snapshot

    Name Description PowerState
    ---- ----------- ----------
    A_Snapshot Test PoweredOff


    Note that the output above isn’t very well formed, so I prefer to export the results to a CSV file:
  • Get-VM Get-Snapshot export-csv -path c:\temp\VMsnapshots.csv

    Unfortunately the CSV output exports the the VM object as the object type instead of the properties in the object, so you can also use:
  • Get-VM Get-Snapshot foreach-object {$out= $_.VM.Name + "," + $_.Name + "," + $_.Description + "," + $_.PowerState; $out}

Notes

  • I doubt VMware would recommend querying the database directly, they’d say to use their SDK or the VI toolkit instead of either one or two above.
  • The SQL commands above add GMT+10 to the UTC times recorded in the database using DateAdd()


Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Comparing MSCS/VMware/DFS File & Print

The following table shows information I was using to compare various Windows HA file and print solutions, including MSCS, VMware, VMware+MSCS, DFS, VMware+DFS and stand-alone servers. There are no recommendations, and most need to be adjusted or at least considered for your environment, but it might help crystalise your thoughts as it did mine.


Comparison Microsoft server ClusteringVMware HAMicrosoft Clustering on VMware HADFSStand-alone server(s)VMware HA with DFS for file shares
Highly AvailableYYYNNY
Satisfies SLAs??????
Maximum nodes8Limited by host hardware2N/AN/ALimited by host
Failover time<2 minutesVMotion or server startup time<2 minutesSPFSPFVMotion or server startup time
Single server Disaster Recovery – Software Failure<2 minutesSnapshot, server rebuild or manual recovery procedure<2 minutesSPFSPFpshot, server rebuild or manual recovery procedure
Single server Disaster Recovery – Hardware Failure<2 minutes< 30 seconds< 30 secondsSPFSPF< 30 seconds
Licensing2003 Enterprise per nodeDataCentre + CALs (depending on VM design)DataCentre + CALs (depending on VM design)2003 Standard2003 Standard2003 Standard
Hardware Failure – Data CommunicationsSingle/teamed NIC for prod interfaceNIC redundancy depending on virtual solution NIC redundancy depending on virtual solution + cluster-specific requirementsTeamed NICTeamed NICNIC redundancy depending on virtual solution
Hardware Failure – HBASingle HBA per nodeHBA redundancy depending on virtual solutionHBA redundancy depending on virtual solutionSingle HBASingle HBAHBA redundancy depending on virtual solution
OS Disk ConfigurationBasic DynamicBasicDynamicDynamicDynamic
Hardware utilisationPhysical serversVirtual serversVirtual serversPhysical serversPhysical serversVirtual servers
Cost allocationCost model requiredCost model requiredCost model requiredPer server/LUNPer server/LUNCost model required
Scalability/Flexibility – adding new nodes/LUNsYYYNNY, DFS for file
ManageabilityMSCS skills requiredVMware skills requiredComplex combination of both technologiesDFS skills requiredExisting skills, but increased per serverDFS and VMware skills required
User access to shares via UNCSingle nameMultiple namesSingle nameSingle nameMultiple namesDFS namespace
Future proofing – migration to new hardware/OSModerately complicated migrationRelatively simple upgrade path, reattaching LUNs or adding another VMModerately complicated migrationRelatively simpleRelatively simpleRelatively simple
Hardware on Vendor HCL??????
Backup/restore?Standard file backupVCB or ?Standard file backupStandard file backupVCB or ?
Printer administrationSimplified with Cluster 2003Duplicated effort on each print serverSimplified with Cluster 2003N/ADuplicated effort on each print serverDuplicated effort on each print server
Service and Event MonitoringCluster monitoring requiredStandard monitoring for virtual servers, host monitoring requiredCluster monitoring for virtual servers, VMware host monitoring requiredStandard monitoringStandard monitoringStandard monitoring for virtual servers, host monitoring required


1. Basic disks on a Microsoft server cluster can be extended if new space is visible on the LUN. The disks cannot be dynamic in MSCS.
See http://technet2.microsoft.com/windowsserver/en/library/cd4d0a84-6712-4fbc-b099-2e8fefeb694c1033.mspx?mfr=true


Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

Modifying Exchange mailbox permissions

Two methods are discussed in this post regarding command-line modifications to Exchange 2003 mailbox security, VBScript and ADModify.Net.

Method 1 - VBScript

The first method is to use a VBScript - modifying exchange mailbox rights can be done in a very similar fashion to modifying the ntSecurityDescriptor attribute. However, to make this work you need CDOEXM installed, installed with the exchange console on your administrative workstation.

The CDOEXM (Collaboration Data Objects for Exchange Management) objects provide an interface called IExchangeMailbox. This interface inherits from IMailboxStore, and also provides an additional property key to modifying Exchange permissions - the MailboxRights property.

Instead of using the msExchMailboxSecurityDescriptor attribute, you need to get and set the DACL using the MailboxRights property. The msExchMailboxSecurityDescriptor is only a back-link from the Exchange store, it doesn’t have a matching forward-link - therefore it won't be replicated if you modify this AD attribute. It eventually would be overwritten when the DACL is replicated back from the exchange mailbox object.

I assume the reason for the backlink msExchMailboxSecurityDescriptor attribute is mostly convenience and backwards compatibility, ie, an application or an admin can read the Exchange permissions (excluding inheritance I think) without requiring CDO.

Note that the Microsoft references below provide example script on using MailboxRights to modify existing mailboxes, and although the articles are quite good and very detailed, the relevance of MailboxRights compared to msExchMailboxSecurityDescriptor wasn't immediately obvious (to me at least).

Method 2 - ADModify.Net

The second method is to use ADModify.Net - a very powerful (and therefore potentially dangerous) utility to perform bulk modifications on mailbox objects. It comes with both command-line and GUI versions.

admodcmd is the command-line version, and the following example command starts at the specified DN, filtering based on user accounts with a certain CN, and then adds full-access mailbox rights to these users for the specified group:

admodcmd -dn "OU=USERS,DC=domain,DC=com" -f "(&(objectClass=user)(objectCategory=person)(CN=user*))" -addtomailboxrights domain\GroupToAdd ACE_MB_FULL_ACCESS


Issuing Query....

12 items found matching the specified filter.


0% 50% 100%
----------------------------------------
...................................................

Successful changes: 12
Already set to specified value: 0
Failed changes: 0

Operation Completed in 4.15625 seconds.


References

How to set Exchange Server 2003 and Exchange 2000 Server mailbox rights on a mailbox that exists in the information store
http://support.microsoft.com/?id=310866

How to set Exchange Server 2000 and 2003 mailbox rights at the time of mailbox creation
http://support.microsoft.com/kb/304935

Exchange 2003 SP2 Disabling Mapi/Non-Cached Access Per User
http://technet.microsoft.com/en-us/library/bb219050(EXCHG.65).aspx

ADModify.NET - Home
http://www.codeplex.com/admodify


Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.


Read more!

All Posts

printQueue AD objects for 2003 ClusterVirtualCenter Physical to VirtualVirtual 2003 MSCS Cluster in ESX VI3
Finding duplicate DNS recordsCommand-line automation – Echo and macrosCommand-line automation – set
Command-line automation - errorlevels and ifCommand-line automation - find and findstrBuilding blocks of command-line automation - FOR
Useful PowerShell command-line operationsMSCS 2003 Cluster Virtual Server ComponentsServer-side process for simple file access
OpsMgr 2007 performance script - VMware datastores...Enumerating URLs in Internet ExplorerNTLM Trusts between 2003 and NT4
2003 Servers with Hibernation enabledReading Shortcuts with PowerShell and VBSModifying DLL Resources
Automatically mapping printersSimple string encryption with PowerShellUseful NTFS and security command-line operations
Useful Windows Printer command-line operationsUseful Windows MSCS Cluster command-line operation...Useful VMware ESX and VC command-line operations
Useful general command-line operationsUseful DNS, DHCP and WINS command-line operationsUseful Active Directory command-line operations
Useful command-linesCreating secedit templates with PowerShellFixing Permissions with NTFS intra-volume moves
Converting filetime with vbs and PowerShellDifference between bat and cmdReplica Domain for Authentication
Troubleshooting Windows PrintingRenaming a user account in ADOpsMgr 2007 Reports - Sorting, Filtering, Charting...
WMIC XSL CSV output formattingEnumerating File Server ResourcesWMIC Custom Alias and Format
AD site discoveryPassing Parameters between OpsMgr and SSRSAnalyzing Windows Kernel Dumps
Process list with command-line argumentsOpsMgr 2007 Customized Reporting - SQL QueriesPreventing accidental NTFS data moves
FSRM and NTFS Quotas in 2003 R2PowerShell Deleting NTFS Alternate Data StreamsNTFS links - reparse, symbolic, hard, junction
IE Warnings when files are executedPowerShell Low-level keyboard hookCross-forest authentication and GP processing
Deleting Invalid SMS 2003 Distribution PointsCross-forest authentication and site synchronizati...Determining AD attribute replication
AD Security vs Distribution GroupsTroubleshooting cross-forest trust secure channels...RIS cross-domain access
Large SMS Web Reports return Error 500Troubleshooting SMS 2003 MP and SLPRemotely determine physical memory
VMware SDK with PowershellSpinning Excel Pie ChartPoke-Info PowerShell script
Reading web content with PowerShellAutomated Cluster File Security and PurgingManaging printers at the command-line
File System Filters and minifiltersOpsMgr 2007 SSRS Reports using SQL 2005 XMLAccess Based Enumeration in 2003 and MSCS
Find VM snapshots in ESX/VCComparing MSCS/VMware/DFS File & PrintModifying Exchange mailbox permissions
Nested 'for /f' catch-allPowerShell FindFirstFileW bypassing MAX_PATHRunning PowerSell Scripts from ASP.Net
Binary <-> Hex String files with PowershellOpsMgr 2007 Current Performance InstancesImpersonating a user without passwords
Running a process in the secure winlogon desktopShadow an XP Terminal Services sessionFind where a user is logged on from
Active Directory _msdcs DNS zonesUnlocking XP/2003 without passwords2003 Cluster-enabled scheduled tasks
Purging aged files from the filesystemFinding customised ADM templates in ADDomain local security groups for cross-forest secu...
Account Management eventlog auditingVMware cluster/Virtual Center StatisticsRunning scheduled tasks as a non-administrator
Audit Windows 2003 print server usageActive Directory DiagnosticsViewing NTFS information with nfi and diskedit
Performance Tuning for 2003 File ServersChecking ESX/VC VMs for snapshotsShowing non-persistent devices in device manager
Implementing an MSCS 2003 server clusterFinding users on a subnetWMI filter for subnet filtered Group Policy
Testing DNS records for scavengingRefreshing Computer Account AD Group MembershipTesting Network Ports from Windows
Using Recovery Console with RISPAE Boot.ini Switch for DEP or 4GB+ memoryUsing 32-bit COM objects on x64 platforms
Active Directory Organizational Unit (OU) DesignTroubleshooting computer accounts in an Active Dir...260+ character MAX_PATH limitations in filenames
Create or modify a security template for NTFS perm...Find where a user is connecting from through WMISDDL syntax in secedit security templates

About Me

I’ve worked in IT for over 20 years, and I know just about enough to realise that I don’t know very much.