2015-11-16

Rename Active Directory groups with PowerShell

I was struggling with this one because there are several different name attributes for AD objects, name, DisplayName, SamAccountName, cn, etc.

I finally ended up with this solution which seems to rename all name attributes:


Import-Module ActiveDirectory

$TargetGroups = Get-ADGroup -Filter {Name -like "XXXDescription*"}

ForEach($SingleGroup in $TargetGroups)
{
    Write-Host "Old name: $($SingleGroup.Name)"
    $NewGroupName = $($SingleGroup.Name).Replace('XXXDescription','YYYYZZZZDescription')
    Write-Host "New name: $($NewGroupName)"
    Get-ADGroup $SingleGroup | Set-ADGroup -DisplayName $NewGroupName -SamAccountName $NewGroupName
    Get-ADGroup $SingleGroup | Rename-ADObject -NewName $NewGroupName
}
If there is a nicer solution, please feel free to post it in the comments.

2015-09-24

Ping servers from a text file

This may look very simple ... but it took me some time to figure out :-(

I am on a Linux box and have a text file with server names / IPs that I want to ping.

How can I do that in a one-liner?

Here is what helped me:

cat [path to textfile] | xargs -n1 ping -c 2


Now I am still looking for a PowerShell one-liner to do something similar.

If you know one, please let me know in the comments.

2015-09-02

Collect disk space data from remote servers

A little PowerShell Script that collects disk space data from remote servers.

I found this practical to collect statistical data.

###############################################################
_#####################
# This script counts and calculated available and free disk
_ spare on remote servers
# # A WMI query is used to collect the data # # Target servers and disks are in a separate comma-delimited
_ text file
###############################################################
_#####################
# Input file location $InputFile = "ServersAndDisks.txt" # Loop through each line of the input file ForEach ($Line in $(Get-Content $InputFile)) { # Write line data into an array $Data = $Line.Split(",") # Get the server name (always first element of the array) $ServerName = $Data[0] write-host $ServerName # Loop through the remaining elements of the array to find
_ available disks
For ($Count = 1; $Count -le $Data.GetUpperBound(0); $Count++) { # Get the disk name $Disk = $Data[$Count] # Run the WMI query $DiskInfo = Get-WmiObject Win32_LogicalDisk -ComputerName
_$ServerName
-Filter "DeviceID='$Disk'" # Do some math on the data $DiskTotal = [math]::Round($DiskInfo.Size / 1GB, 1) $DiskFree = [math]::Round($DiskInfo.FreeSpace / 1GB, 1) $PercentageFree = [math]::Round($DiskInfo.FreeSpace /
_$DiskInfo
.Size * 100, 1) # Output the results Write-Host "$Disk - $DiskTotal GB Total / $DiskFree GB free
_ ($PercentageFree %)"
} }


The input file ServersAndDisks.txt is very simple - only a comma-delimited file with server name and the disks I want to check:
server001,C:,D:
server002,C:,D:
server003,D:

2015-08-26

Fixing Windows 10 to run Firefox & Chrome after OS upgrade

Just upgraded from Windows 7 Home to Windows 10.

Firefox & Chome would not connect to the network.

Here is what helped me:
  1. Started elevated cmd
  2. Executed netsh winsock reset
  3. Rebooted

PS: I had to do this for each (local) user account  on the box.

2012-02-12

Get the MAC address of a remote computer

OK, this might really be very, very basic ... but it is still often useful.
How to get the MAC address of a remote computer (limitation: the computer must be on the same IP subnet) from a Windows command line?

Ping the computer (either the hostname or the IP address)
Then run arp -a
It will return a list of IP addresses and the associated MAC addresses.
Look for the line that has the IP of the computer in question and you have its MAC address.

Background:
We are making use of the ARP cache. The arp cache keeps track of the next (router-) hop to any given IP address. If there are no routers involved (i.e. on the same subnet) the MAC address of the computer is returned. If however the traffic needs to be routed then the MAC address of the next router is returned.




2011-12-24

VMware Player vs. Virtual Network Editor

Those of us that work with VMware Workstation and use multiple networks (physical NICs or VLANs) on the host computer, are used to work with the Virtual Network Editor. This tool assigns network connections on the physical host to virtual networks. A VM can then be assigned to a virtual network adapter that is linked to a specific adapter on the physical host.

It may seem that this tool is missing if one has only the VMware Player at hand. But it comes with the installation package - it just needs to be extracted.

Follow these steps to extract the Virtual Network Editor: (in the example below D:\Downloads\ is the download location)

  1. Download the VMware Player installation package (needs a registration with VMware)
  2. Open a command line and change to D:\Downloads\
  3. Run the following command: [VMware Player installation package] /e ./Extract (this will extract the contents to a subfolder "Extract")
  4. Open the subfolder Extract and look into the network.cab file
  5. Extract the files inside the .cab file into the VMware Player installation folder
  6. Run vmnetcfg.exe if you need the Virtual Network Editor



2011-09-02

Accessing IE from vbScript

It used to be simple to use Internet Explorer as output for vbScripts. Here is a sample script that opened a custom HTML page and then writes something into a <div id="Status">...</div> stanza.

Dim objIE
Set objIE = WScript.CreateObject ("InternetExplorer.Application")
objIE.Width = 700
objIE.Height = 250
objIE.Toolbar = false
objIE.statusbar = false
objIE.Navigate "D:\Test\Output.html"
objIE.Visible = true
objIE.document.all.Status.InnerHTML = "<font color='#0063FF'><b>Done... waiting 5 secs...</b></font>"
WScript.Sleep (5000)
objIE.Quit


Now with Windows 7 and IE 9 many of those scripts do no longer run but throw errors. Common errors are for example: "The object invoked has disconnected from its client." (80010108) or "Unspecified error" (80004005)

It seems that the original Internet Explorer object gets lost because the web page is loaded into a child process of IE. So any reference to it from a vbScript fails.

A few changes to the above script can work around that issue. It may not be the most elegant but it is working so far.

Dim objIE
Set objIE = WScript.CreateObject ("InternetExplorer.Application")
Set objShellApp = CreateObject("Shell.Application")
objIE.Width = 700
objIE.Height = 250
objIE.Toolbar = false
objIE.statusbar = false
objIE.Navigate "D:\Test\Output.html"
objIE.Visible = true
Set objIE = Nothing
For Each objWindow In objShellApp.Windows
If LCase(objWindow.LocationName) = LCase("Output.html") Then
Set objIE = objWindow
End If
Next
objIE.document.all.Status.InnerHTML = "<font color='#0063FF'><b>Done... waiting 5 secs...</b></font>"
WScript.Sleep (5000)
objIE.Quit

Basically we are looping through all windows and connect (hopefully ;-) ) to the one that has our HTML file open.