header image

Archive for October, 2011

Quick revision to the post on reading the hosts file http://msmvps.com/blogs/richardsiddaway/archive/2011/10/23/reading-the-hosts-file.aspx. I wanted to be able to display the whole file function get-hostfilecontent { param ([switch]$all) $file = Join-Path -Path $($env:windir) -ChildPath "system32\drivers\etc\hosts" if (-not (Test-Path -Path $file)){ Throw "Hosts file not found" } $cont = Get-Content -Path $file if ($all) { $cont } else […]

under: Networking, PowerShellV2

Multiple value query in WQL

Posted by: | October 31, 2011 | No Comment |

A simple query that demonstrates how to query for multiple values. We want to stop the running services that are running where the names a like BITS and WinRm Get-WmiObject -Class Win32_Service -Filter "State=’Running’ AND Name LIKE ‘%BITS%’ OR Name LIKE ‘%WinRM%’" | Invoke-WmiMethod -Name StopService   Define the service state and use AND to […]

under: PowerShell and WMI, PowerShell Basics

In this post – http://msmvps.com/blogs/richardsiddaway/archive/2011/10/23/1760058.aspx – I showed how to get the date of the last update applied to a system.  A comment was posted asking how to log machines that can’t be contacted ".", "rslaptop01", "200.0.0.1" | foreach { if (Test-Path -Path hotfix.log){Remove-Item -Path hotfix.log -Force} if(-not(Test-Connection -ComputerName $_ -Count 1 -Quiet)){ Add-content -Path […]

under: PowerShell and WMI

Clearing hosts file

Posted by: | October 30, 2011 | No Comment |

We seen how to delete a single entry from the hosts file – this is how we clear all entries function clear-hostfilecontent { [CmdletBinding()] param () $file = Join-Path -Path $($env:windir) -ChildPath "system32\drivers\etc\hosts" if (-not (Test-Path -Path $file)){ Throw "Hosts file not found" } Write-Verbose "Remove IP Addresses" $data = ((Get-Content -Path $file) -notmatch "^\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b") […]

under: Networking, PowerShellV2

A must read if you are interested in any of these http://blogs.technet.com/b/server-cloud/archive/2011/10/14/windows-server-8-standards-based-storage-management.aspx   WMI is getting everywhere these days – better learn it quick

under: PowerShell and WMI, PowerShell V3, Windows 8 Server

Remove a host file record

Posted by: | October 26, 2011 | No Comment |

Next up is removing a record from a hosts file function remove-hostfilecontent { [CmdletBinding()] param ( [parameter(Mandatory=$true)] [ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")] [string]$IPAddress, [parameter(Mandatory=$true)] [string]$computer ) $file = Join-Path -Path $($env:windir) -ChildPath "system32\drivers\etc\hosts" if (-not (Test-Path -Path $file)){ Throw "Hosts file not found" } Write-Verbose "Remove IP Address" $data = ((Get-Content -Path $file) -notmatch "$ip\s+$computer") $data Set-Content -Value $data […]

under: Networking, PowerShellV2

Minor rant

Posted by: | October 25, 2011 | 2 Comments |

Why do software suppliers – Adobe with Acrobat Reader & Oracle with Java are the worst culprits – insist on trying to install their browser toolbar & change my default search engine?? What’s worse is that they make the default action to install it & I have to remember each and every time their products […]

under: Rant

Four new chapters have been added to the MEAP  (early access) for PowerShell and WMI Chapter 14 – Users and security Chapter 15 – Logs, jobs, and performance Chapter 16  – Hyper-V Chapter 17 – Windows Remote Management   Chapter 17 deals with using WMI over the WSMAN cmdlets   The MEAP is available from […]

under: PowerShell and WMI

Hosts file – add a record

Posted by: | October 24, 2011 | 2 Comments |

We’ve seen how to read the Hosts file – this is how we add a record function add-hostfilecontent { [CmdletBinding(SupportsShouldProcess=$true)] param ( [parameter(Mandatory=$true)] [ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")] [string]$IPAddress, [parameter(Mandatory=$true)] [string]$computer ) $file = Join-Path -Path $($env:windir) -ChildPath "system32\drivers\etc\hosts" if (-not (Test-Path -Path $file)){ Throw "Hosts file not found" } $data = Get-Content -Path $file $data += "$IPAddress $computer" […]

under: Networking, PowerShellV2

Reading the hosts file

Posted by: | October 23, 2011 | No Comment |

Normally I ignore the Hosts file but my development laptop isn’t a member of my test domain – a number of reasons for this which I won’t go into. This means that when I want to RDP to a machine in the test domain I have to use the IP address. A bit awkward but […]

under: Networking, PowerShellV2

Older Posts »

Categories