PowerShell for Windows Admins:

Powershell


July 7, 2017  8:03 AM

Variable as a where clause

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

A post on the forum about using a variable as a where clause looked interesting. What the user wanted to do was to define a variable that contained the filter to be used by Where-Object. As an example consider filtering the output of Get-Service to display only services that are...

July 5, 2017  1:39 PM

File name starting with space

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Interesting question on the forum regarding finding files with a file name starting with a space. First problem was creating some files to match the criteria. Renaming in file explorer didn’t work so back to PowerShell

PS> Rename-Item -Path C:\test\file1.txt -NewName "C:\test\...


July 3, 2017  12:52 PM

Topics for PowerShell Summit 2018

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

The planning for Summit 2018 has started – to be honest it started before Summit 2017 opened. We’ve reached the stage where we need to start thinking about the broad topics for PowerShell Summit 2018. What do you want to hear about? Not the session titles, content and speakers but the broad...


July 1, 2017  1:06 PM

MVP 2017

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

I received the email this afternoon stating I’d received an MVP award for 2017-2018 for my work with PowerShell. This is the 10th consecutive year I’ve been honoured with an MVP award. Its as big an honour to receive the 10th as it was to receive the first.


June 30, 2017  12:59 PM

Finding a CIM class

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

One of the problems you might find is finding a CIM class. You know its name but you don’t know which namespace its in. The old WMI cmdlets allow you to search the namespaces recursively

PS> Get-WmiObject -Class Win32_Process -Namespace root -Recurse -List


 NameSpace:...


June 29, 2017  2:56 PM

Joining and Testing folder paths

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Last time I showed how to split folder paths to just leave the path – no filenames or drive information. What about the opposite task – joining and testing folder paths. Here’s an example

$basepath = 'C:\Scripts'

$pathsTotest = 'Containers','HyperV', 'NanoServer',...


June 29, 2017  1:50 PM

Just the folders

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Lets say you have a bunch of files in nested folders but you want just the folders not the file or drive Our files look like this

C:\Scripts\HyperV\Setup
 C:\Scripts\HyperV\attachdisks.ps1
 C:\Scripts\HyperV\get-mountedvhdDrive.ps1
 C:\Scripts\HyperV\invoke-CIMshutdown.ps1
...


June 28, 2017  12:42 PM

Location, location

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Just recently I’ve found my self repeatedly working through a location, location pattern.

cd C:\test\
 .\hello.ps1
 cd C:\Scripts\
The pattern consists of changing to another folder. Running some code and then changing back to the original folder – assuming you can remember...


June 27, 2017  2:01 PM

$using

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

A comment on yesterday’s post about passing parameters into a script block asked why I hadn’t mention $using $using allows you to access a local variable in a scriptblock BUT you need to be careful

PS> $proc = "power*"

Invoke-Command -ScriptBlock {
 Get-Process -Name...


June 27, 2017  10:52 AM

PowerShell on Linux

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

An introduction to PowerShell v6 on Windows, mac and Linux is available here https://blogs.msdn.microsoft.com/powershell/2017/06/09/getting-started-with-powershell-core-on-windows-mac-and-linux/ Well worth a read if you haven’t looked at PowerShell v6 yet


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: