Matching the ESX and storage LUNs

February 23, 2017

It has been always a problem to match LUNs on ESX to LUNs on a storage. Eventually I wrote a short script to make this work way easier

Read the rest of this entry »


Windows Firewall terminates with Access Denied error

February 20, 2017

Honestly speaking I do not know when exactly it happened and why, but one day I found out that the Windows Firewall service on my computer was stopped. Not a big deal, I tried to start it up and got the Access Denied error. Read the rest of this entry »


Pipeline to clipboard in PowerShell

October 2, 2015

Friend of mine has recently shared this trick with me.

If you need a PowerShell command output to be sent to your clipboard to be ready for paste, use the “| clip” command.

for example:

Get-service | clip


Robocopy from NTFS to EXT3

July 21, 2014

Robocopy with the /MIR option copies some files again and again every time it runs even though the files are the same. Obviously, robocopy thinks that the source file is newer.

How could it be? Only if the target file system has larger time stamp resolution. For example, NTFS can write the file date/time with accuracy of 100 ns. Ext3 has accuracy of 1 second only. Therefore, the file time stamp is rounded to 1 sec during the copy from NTFS to EXT3, which can automatically make a file on EXT3 older than the source file on NTFS.

The resolution is simple: robocopy has the /FFT option that uses FAT file time stamp. Accuracy for FAT time stamp is only 2 seconds.


List the Printers in Print Cluster

March 25, 2014

New plans, new projects…

As a part of one of such plans I needed to list all the printers located at the Windows 2000 print cluster (I know, I know what you wanna say). Simple task, one line command can do this

Get-WMIObject win32_Printer -computerName PrintClusterName

Ooops… No printers listed. OK, this print cluster has several resource groups and several virtual names, one per department. Print cluster itself does not have any printer, all are installed within those resource groups

Get-WMIObject win32_Printer -computerName DepartamentalVirtualName

No printers listed.

Short investigation showed that Windows cluster 2000/2003 does not support WMI, so, no way to list the printers.

Good thing is that all those printers were published in Active Directory. This approach worked, not from the first run though.

Search for the PrintQueue object class

$ADRoot = [ADSI]””
$Searcher = New-Object System.Directoryservices.DirectorySearcher($ADRoot)
$Searcher.SearchRoot = $ADRoot
$Searcher.SearchScope = “subtree”
$Searcher.Filter = “(objectClass=PrintQueue)”
$ADPrinters = $Searcher.FindAll()

and be aware that all the object properties are collections and their names are case sensitive.For example, the driver name is available like this

$ADPrinter.Properties.drivername[0] 

That’s it. In addition the script pings IP printer addresses to filter out “forgotten” printers.

The entire script is provided below. It allows to get almost every bit of information we usually see in the Printer Properties window

#####################################################################
#### FUNCTIONS ####################################################
#####################################################################
FUNCTION Ping ($Device)
{
$Filter = “Address=” + [char]34 + $Device + [char]34
$PingStatus = Get-WMIObject Win32_PingStatus -Filter $Filter
return (($PingStatus -ne $Null) -and ($PingStatus.StatusCode -eq 0))
}

FUNCTION GetProperty ($PropertyName)
{
if ($ADPrinter.Properties.$PropertyName -eq $Null)
{return “”}
else
{
if ($ADPrinter.Properties.$PropertyName[0] -ne $Null)
{return $ADPrinter.Properties.$PropertyName[0].ToString()}
else
{return $ADPrinter.Properties.$PropertyName.ToString()}
}
}

#####################################################################
#####################################################################
#####################################################################

#####################################################################
#### INITIALIZING THE VARIABLES
#####################################################################
$InfoMessage = $Host.PrivateData.WarningForeGroundColor
$ErrorMessage = $Host.PrivateData.ErrorForeGroundColor
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path

############################################################
$OutputFileName = (Read-Host “Enter the result file name”).Trim()
if ($OutputFileName -ne “”)
{
if ($OutputFileName.IndexOf(“:”) -eq -1)
{$OutputFileName = Join-Path $ScriptPath $OutputFileName}
if ((Test-Path $OutputFileName) -eq $True)
{
Write-Host ($OutputFileName + ” already exists”) -foregroundColor $ErrorMessage
return
}
Add-Content $OutputFileName -value “Virtual Cluster Name;Printer Name;Port Name;IP Address;Share Name;Driver Name;Creation Date;Location;Description;Active”
}

#####################################################################
#### MAIN LOOP
#####################################################################

$ADRoot = [ADSI]””
$Searcher = New-Object System.Directoryservices.DirectorySearcher($ADRoot)
$Searcher.SearchRoot = $ADRoot
$Searcher.SearchScope = “subtree”
$Searcher.Filter = “(objectClass=PrintQueue)”
$ADPrinters = $Searcher.FindAll()
Write-Host “Searching for the printers in Active Directory…”

ForEach ($ADPrinter in $ADPrinters)
{
Write-Host “.” -noNewLine

$Line = (GetProperty “shortservername”) + “;” + (GetProperty “printername”) + “;” + (GetProperty “portname”) + “;”

$Active = “Incorrect Port Name”
$IPAddress = “”
if ($ADPrinter.Properties.portname[0] -match “IP_(.*)”)
{
$IPAddress = $Matches[1]
if ((Ping $IPAddress))
{$Active = “YES”}
else
{$Active = “No”}
}

$Line = $Line + $IPAddress + “;” + (GetProperty “printsharename”) + “;” + (GetProperty “drivername”) + “;” + (GetProperty “whencreated”) + “;”
$Line = $Line + (GetProperty “location”) + “;” + (GetProperty “description”)
$Line = $Line + “;” + $Active
Add-Content $OutputFileName -value $Line
}
Write-Host

return

 

 


Setting up the Programmatic Access in Outlook 2007/2010

September 24, 2012

For a PCI-related product we have recently installed, I’ve needed to run a script that reads an Outlook mailbox and analyze the message content. Nothing special, but Outlook stops script with the following message

Read the rest of this entry »


How to Elevate Privileges from Command Line

August 21, 2011

My task has been pretty simple: I have needed to run a batch file with a lot of Robocopy commands. The issue I have faced is usual for Windows Vista, Windows 7 or Windows Server 2008:

ERROR: You do not have the Backup and Restore Files user rights.

Yes, if I right click on the batch file and select Run As Administrator, everything works fine. My goal has been to run this batch file from the command line without user interaction at all. At the same time I have needed not to compromise security

Read the rest of this entry »