Don’t expect to be anywhere but in front of your computer between 26 April and 7 May. Why? because the 2010 Scripting Games are happening. The usual 10 events with beginners and advanced versions. A whole bunch of expert commentators – including me. For more information and a few hints on things that could […]
Archive for March, 2010
Book Review: Windows PowerShell 2.0 Best Practices
Posted by: richardsiddaway | March 23, 2010 | 2 Comments |Author: Ed Wilson and Windows PowerShell Teams at Microsoft Publisher: Microsoft Press ISBN: 978-0-7356-2646-1 I have three main criteria for judging a book: Is it technically accurate? Does deliver the material it claims to deliver? Is worth the cost of purchase and the time I spend reading it? Before diving into the review I have […]
Since PowerShell 2.0 appeared I have been steadily converting a lot of scripts to modules. Up until now I have been using a single .psm1 file (and possibly a .psd1 file for the manifest). The .psm1 file contains all of the functions. Some of my .psm1 files are getting a bit unwieldy so I decided […]
Problem How can I prevent the creation of folders with spaces in the name from within my script. Solution 001 002 003 004 005 006 007 008 009 010 function New-Folder { param ( [string]$path = "C:\Test", [string]$name = "" ) if($name.Indexof(" ") -ge 0){throw "Folder name contains spaces"} if (!(Test-Path -Path $path)){throw "Invalid path"} if ($name -eq ""){throw "Invalid folder name"} New-Item -Path $path -Name $name -ItemType directory } Define the path […]
In my scripts I usually create variables as $a = 3 or similar. There are a number of cmdlets for working with variables Clear-Variable Get-Variable New-Variable Remove-Variable Set-Variable Lets start with get-variable PS> Get-Variable Name Value —- —– $ *variable ? True ^ Get-Command _ args {} ConfirmPreference High ConsoleFileName DebugPreference SilentlyContinue Error {} ErrorActionPreference […]
I came across this interesting problem and thought it was worth a post. Problem You have a folder with a set of files with names like this Black or Blue [15665782345].txt Black or Green [1068682345].txt Black or White [12345].txt Black or Yellow [A2G345].txt Blue or Green [14786862345].txt Pink or Yellow [12345465785].txt Purple or Gold [345612345].txt […]
The last of our path cmdlets is Convert-Path. This converts a PowerShell path to a PowerShell provider path. This sequence should explain how it works. PS> cd HKLM: PS> cd software PS> cd microsoft PS> Get-Location Path —- HKLM:\software\microsoft PS> Convert-Path -Path (Get-Location) HKEY_LOCAL_MACHINE\software\microsoft change drive to the HKLM: registry drive navigate into […]
Resolve-Path is interesting in that Resolve-Path c:\scripts\* "c:\scripts\*" | Resolve-Path both supply a listing of the contents of the folders. A sample is shown C:\scripts\WMICookBook C:\scripts\WPF C:\scripts\XML C:\scripts\auto.csv C:\scripts\computers.txt C:\scripts\emptyfolders.txt C:\scripts\encrypted.txt C:\scripts\firewall.ps1 C:\scripts\import-mymodule.ps1 It shows files and subfolders with no way to distinguish. There isn’t a way to recurse through sub folders A System.Management.Automation.PathInfo […]
Two related cmdlets deal with paths – split-path and join-path. Starting with split-path we can use it to split the path to retrieve the file or directory PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 C:\Scripts\DC02\Scripts\DNS PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 -Parent C:\Scripts\DC02\Scripts\DNS PS> Split-Path -Path C:\Scripts\DC02\Scripts\DNS\new-mx.ps1 -Leaf new-mx.ps1 The default gives the parent container. We can also separate the […]
There are a number of cmdlets for working with paths PS> Get-Command *path | select Name Name —- Convert-Path Join-Path Resolve-Path Split-Path Test-Path Test-Path is the one I probably use most PS> Test-Path -Path "C:\Users\Richard\Documents\PowerShell in Practice\TODO.txt" True PS> Test-Path -Path "C:\Users\Richard\Documents\PowerShell in Practice\Chapter1.docx" False It returns a Boolean – true if the path […]
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