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 […]
Archive for October, 2011
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 […]
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 […]
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") […]
PowerShell, Storage, WMI and Windows Server 8
Posted by: richardsiddaway | October 26, 2011 | No Comment |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
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 […]
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 […]
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 […]
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" […]
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 […]
Categories
- .NET
- Active Directory
- Architecture
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File System
- Firewall
- General
- General IT Matters
- Hyper-V
- IIS
- Infrastructure
- IT Community
- IT Security
- Learning PowerShell
- Linux
- Math
- Microsoft
- Modules
- Nano Server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- PowerShell
- PowerShell 7
- PowerShell and .NET
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- PowerShell Basics
- PowerShell original
- PowerShell Summit
- PowerShell User Group
- PowerShell User Group 2
- PowerShell v2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- PowerShell.org
- PowerShellGet
- PowerShellV2
- PSAM
- Rant
- Registry
- Scripting
- Scripting Games
- Scripting Games 2104
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualization
- Windows 10
- Windows 2012 R2
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSUS