I really missed the Print Screen button on my Surface Pro Type Cover for a long time. Just recently I found out that it was there all the time :-(
[Fn] + [Space]
It can also be combined with other keys like [Alt] + [Fn] + [Space]
I have no idea what took me so long to figure it out ...
2016-01-13
2016-01-01
Checking for reboots
Sometime we schedule reboots on a machine and would like to know the next day if the reboots were successful or not.
The easiest approach for me is to look for event log entries that show that the Event Log service was started.
This can be done by filtering inside the Event Log console but I prefer this PowerShell one-liner that checks for these entries during the past 24 hours:
The easiest approach for me is to look for event log entries that show that the Event Log service was started.
This can be done by filtering inside the Event Log console but I prefer this PowerShell one-liner that checks for these entries during the past 24 hours:
Get-EventLog -After
$(Get-Date).AddHours(-24) -EntryType Information -Source
EventLog -LogName
System |
Where {$_.EventID -eq "6005"}
2015-11-19
Quick glance at PowerShell environment
Logging in to a new system and need to know what my PowerShell capabilities are.
To have a quick overview of what I can do on that box I do this:
To have a quick overview of what I can do on that box I do this:
Write-Host "Installed
PowerShell version: $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)"
Write-Host "Available
PowerShell modules:"
Get-Module -ListAvailable
| Select Name
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:
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:
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.
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.
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:
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 %)" } }
_##################### # 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:
PS: I had to do this for each (local) user account on the box.
Firefox & Chome would not connect to the network.
Here is what helped me:
- Started elevated cmd
- Executed netsh winsock reset
- 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.
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)
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)
- Download the VMware Player installation package (needs a registration with VMware)
- Open a command line and change to D:\Downloads\
- Run the following command: [VMware Player installation package] /e ./Extract (this will extract the contents to a subfolder "Extract")
- Open the subfolder Extract and look into the network.cab file
- Extract the files inside the .cab file into the VMware Player installation folder
- 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.
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.
Basically we are looping through all windows and connect (hopefully ;-) ) to the one that has our HTML file open.
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.
2011-08-05
Find duplicate MAC addresses #2
In the previous post about finding duplicate MAC addresses in a vSphere cluster we basically used a PowerCLI one-liner (http://adminthoughtcollection.blogspot.com/2011/05/find-duplicate-mac-addresses.html). That was straight forward but you had to dig through a long list of output and basically had to do the search & find manually.
Today's script makes use of a PowerShell hash table. It's output contains only the duplicate MAC addresses and the conflicting VMs.
Basically all MAC addresses get written into the hash table. But before writing them into it a lookup is performed. If the current MAC address has been written to the hash table before it must obviously be a duplicate.
Today's script makes use of a PowerShell hash table. It's output contains only the duplicate MAC addresses and the conflicting VMs.
Basically all MAC addresses get written into the hash table. But before writing them into it a lookup is performed. If the current MAC address has been written to the hash table before it must obviously be a duplicate.
# Get all VMs and their MAC addresses
$VMdata = Get-VM | Get-NetworkAdapter | select MacAddress,Parent
# Initialize the lookup hash table
$VMlookup = @{}
# Loop through all VMs one-by-one
ForEach ($SingleVM in $VMdata)
{
# If the MAC address is already in the lookup hash table it is a duplicate
if ($VMlookup.ContainsKey($SingleVM.MacAddress))
{
$VMOneNet = (Get-VM $($VMlookup.$($SingleVM.MacAddress)) | Get-NetworkAdapter | Where {$_.MacAddress -eq $SingleVM.MacAddress}).NetworkName
$VMTwoNet = (Get-VM $SingleVM.Parent | Get-NetworkAdapter | Where {$_.MacAddress -eq $SingleVM.MacAddress}).NetworkName
Write-Host "$($SingleVM.MacAddress)" -NoNewLine -ForegroundColor Green
Write-Host " is a duplicate in:"
Write-Host " * $($VMlookup.$($SingleVM.MacAddress)) [$VMOneNet]" -ForegroundColor Yellow
Write-Host "and in:"
Write-Host " * $($SingleVM.Parent) [$VMTwoNet]" -ForegroundColor Yellow
Write-Host
}
# Otherwise it is (still) a unique MAC
else
{
$VMlookup.Add($SingleVM.MacAddress, $SingleVM.Parent)
}
}
Update 2011-08-15: script now also displays the network of the NIC with the conflicting MAC address
$VMdata = Get-VM | Get-NetworkAdapter | select MacAddress,Parent
# Initialize the lookup hash table
$VMlookup = @{}
# Loop through all VMs one-by-one
ForEach ($SingleVM in $VMdata)
{
# If the MAC address is already in the lookup hash table it is a duplicate
if ($VMlookup.ContainsKey($SingleVM.MacAddress))
{
$VMOneNet = (Get-VM $($VMlookup.$($SingleVM.MacAddress)) | Get-NetworkAdapter | Where {$_.MacAddress -eq $SingleVM.MacAddress}).NetworkName
$VMTwoNet = (Get-VM $SingleVM.Parent | Get-NetworkAdapter | Where {$_.MacAddress -eq $SingleVM.MacAddress}).NetworkName
Write-Host "$($SingleVM.MacAddress)" -NoNewLine -ForegroundColor Green
Write-Host " is a duplicate in:"
Write-Host " * $($VMlookup.$($SingleVM.MacAddress)) [$VMOneNet]" -ForegroundColor Yellow
Write-Host "and in:"
Write-Host " * $($SingleVM.Parent) [$VMTwoNet]" -ForegroundColor Yellow
Write-Host
}
# Otherwise it is (still) a unique MAC
else
{
$VMlookup.Add($SingleVM.MacAddress, $SingleVM.Parent)
}
}
Update 2011-08-15: script now also displays the network of the NIC with the conflicting MAC address
2011-08-02
How to Configure Automatic Updates for a Standalone Server
If you want to configure Windows Update on a Server that is not member of a Domain you have two options to do that:
- Using Group Policy Object Editor and editing the Local Group Policy object
- Editing the registry directly by using the registry editor (Regedit.exe)
Using Group Policy Object Editor
Open Group Policy Editor (Local Computer Policy)
Computer Configuration\Administrative Templates\Windows Components\Windows Updates
Set "Configure Automatic Updates" to "Enabled"
Set "Configure automatic updating" to the value you like (Values 2-5)
Set "Scheduled install day:" to the value you like (Values 0-7)
Set "Scheduled install day:" to the time you like
Set "Specify intranet Microsoft updates service location" to "Enabled"
Set "Set the intranet updates service for detecting updates" to your WSUS Server:portnumber
Set "Set the intranet statistic server" to your WSUS Server:portnumber
Set "Automatic Updates detection frequency" to "Enabled"
Set "Check for updates at the following" type interval in hours
Using the Registry Editor
The registry entries for the Automatic Update configuration options are located in the following subkey:
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
For further information look at: Microsoft Technet
2011-06-02
Run command line as NT Authority\System
Another thing that just came up today. I needed a truly elevated command prompt. And by that I mean I needed cmd.exe to run as NT Authority\System.
In the good old days we would just schedule cmd.exe with the good old AT command. (AT 9:08 /interactive "c:\windows\System32\cmd.exe") But what does a current Windows Server 2008 R2 system say to it?
Warning: Due to security enhancements, this task will run at the time
expected but not interactively.
Use schtasks.exe utility if interactive task is required ('schtasks /?'
for details).
Added a new job with job ID = 1
hmm admin is not happy. Starting an interactive cmd.exe using Server Manager's Task Scheduler did also not work.
What helped? psexec from the Sysinternals suite did the job!
Here is the command:
psexec.exe -i -s -d cmd /accepteula
(-i for interactive, -s for NT Authority\System, -d for do not wait for termination of the new cmd.exe, and /accepteula for 'I am in a command line and I do not want to switch to the mouse to click Accept')
In the newly opened command prompt I was really NT Authority\System:
C:\>whoami
nt authority\system
Admin was happy again ;-)
In the good old days we would just schedule cmd.exe with the good old AT command. (AT 9:08 /interactive "c:\windows\System32\cmd.exe") But what does a current Windows Server 2008 R2 system say to it?
Warning: Due to security enhancements, this task will run at the time
expected but not interactively.
Use schtasks.exe utility if interactive task is required ('schtasks /?'
for details).
Added a new job with job ID = 1
hmm admin is not happy. Starting an interactive cmd.exe using Server Manager's Task Scheduler did also not work.
What helped? psexec from the Sysinternals suite did the job!
Here is the command:
psexec.exe -i -s -d cmd /accepteula
(-i for interactive, -s for NT Authority\System, -d for do not wait for termination of the new cmd.exe, and /accepteula for 'I am in a command line and I do not want to switch to the mouse to click Accept')
In the newly opened command prompt I was really NT Authority\System:
C:\>whoami
nt authority\system
Admin was happy again ;-)
2011-05-27
Simple VM inventory using PowerCLI
I needed a script that did a simple inventory of production VMs in a vSphere cluster. The output includes the VM name, its IP addresses (only if VMware Tools are installed), its network names, all .vmdk's and the notes field.
Here is the script:
# We go through all VMs that have a 'Production'-notes entry
$AllPrdVMs = Get-VM | Where {$_.Notes -like "Prod*"} | Sort Name
Foreach ($SingleVM in $AllPrdVMs)
{
$VMName = $SingleVM.Name
# The following two lines enforce the use of an array.
$VMNetwork = @($SingleVM | Get-NetworkAdapter)
$VMHDDs = @($SingleVM | Get-HardDisk)
# The following line only works if VMware Tools are installed
$VMIP = $SingleVM.Guest.IPAddress
$VMNote = $SingleVM.Notes
Write-Host ($VMName) -ForegroundColor Red -NoNewLine
Write-Host (" " + $VMIP) -ForegroundColor Yellow
# Here we loop through the arrays - even if there is only one member
For ($Count = 1; $Count -le $VMNetwork.Length; $Count++)
{
Write-Host $VMNetwork[$Count - 1].NetworkName
}
For ($Count = 1; $Count -le $VMHDDs.Length; $Count++)
{
Write-Host $VMHDDs[$Count - 1].Filename -ForegroundColor Blue
}
Write-Host ($VMNote)
Write-Host
}
PS: First post with syntax-highlighting ;-)
Here is the script:
# We go through all VMs that have a 'Production'-notes entry
$AllPrdVMs = Get-VM | Where {$_.Notes -like "Prod*"} | Sort Name
Foreach ($SingleVM in $AllPrdVMs)
{
$VMName = $SingleVM.Name
# The following two lines enforce the use of an array.
$VMNetwork = @($SingleVM | Get-NetworkAdapter)
$VMHDDs = @($SingleVM | Get-HardDisk)
# The following line only works if VMware Tools are installed
$VMIP = $SingleVM.Guest.IPAddress
$VMNote = $SingleVM.Notes
Write-Host ($VMName) -ForegroundColor Red -NoNewLine
Write-Host (" " + $VMIP) -ForegroundColor Yellow
# Here we loop through the arrays - even if there is only one member
For ($Count = 1; $Count -le $VMNetwork.Length; $Count++)
{
Write-Host $VMNetwork[$Count - 1].NetworkName
}
For ($Count = 1; $Count -le $VMHDDs.Length; $Count++)
{
Write-Host $VMHDDs[$Count - 1].Filename -ForegroundColor Blue
}
Write-Host ($VMNote)
Write-Host
}
PS: First post with syntax-highlighting ;-)
2011-05-26
Remote Session Disconnected
Your remote session may be disconnected with the message: "The remote session was disconnected because the terminal server client access license stored on this computer has been modified"
At this point you should remove the saved terminal server licenses from the client registry. Delete the following key from the registry:
Additional information can be found: http://support.microsoft.com/kb/315262
At this point you should remove the saved terminal server licenses from the client registry. Delete the following key from the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSLicensing
The key will be created the next time you log on to the Terminal Server.Additional information can be found: http://support.microsoft.com/kb/315262
Sessions for Microsoft TechEd 2011 North America are online
Many different sessions are online and downloadable. Security, management, background information etc.
Here is the link to the site:
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011
Here is the link to the site:
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011
Terminal Server Temp Profile
Sometimes users complain because they makes changes in their Windows Terminal Server Session and the settings are lost after they logged out.
The problem is that the User Profile is not saved on a Windows Terminal Server.
You can solve this problem by deleting an entry in the registry:
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
Under this hive you can find a folder for every user. Find the folder with a .bak at the end and delete it.
2011-05-23
Failed HP VCA installation
Just had it today. An HP Version Control Agent (version 6.3.0.870, x64) failed to install. Basically the cp013991.exe crashed under Windows Server 2008 R2. But no real error message.
What helped? Ran the cp013991.exe and selected Extract...
Then in an elevated command prompt I ran the vcagent.msi
Finally got an error message: A previous version was still installed. :-) (A previous update from the HP Version Control Repository had failed, leaving the older version of VCA in an undefined state.)
So I uninstalled the previous version manually and could re-install the current version.
What helped? Ran the cp013991.exe and selected Extract...
Then in an elevated command prompt I ran the vcagent.msi
Finally got an error message: A previous version was still installed. :-) (A previous update from the HP Version Control Repository had failed, leaving the older version of VCA in an undefined state.)
So I uninstalled the previous version manually and could re-install the current version.
Subscribe to:
Posts (Atom)