PowerShell for Windows Admins:

Powershell


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


June 26, 2017  1:43 PM

Passing parameters to a script block

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Passing parameters to a scriptblock seems to be an issue at the moment. Consider a simple scriptblock Invoke-Command -ScriptBlock {Get-Process} How can you modify that to parameterise the processes that are returned. Its a two step process. Add a parameter block to your script block and...


June 26, 2017  10:10 AM

Generating passwords

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
"Computer security", Password, Powershell


June 14, 2017  1:43 PM

Deal of the Day – 15 June 2017

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Books, Hyper-V, Powershell

My book is Manning’s Deal of the Day  - 15 June 2017: Half off Learn Hyper-V in a Month of Lunches. Use code dotd061517au at https://bit.ly/2rZXI9x Sign up for DoD notifications at https://www.manning.com/dotd


June 12, 2017  7:57 AM

Find the logged on user

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

One method of finding the logged on users is to use CIM

$ComputerName = $env:COMPUTERNAME
Get-CimInstance -ClassName Win32_Process -ComputerName $ComputerName -Filter "Name = 'explorer.exe'" | 
foreach {
    
    $lguser = Invoke-CimMethod -InputObject $psitem -MethodName...


May 31, 2017  4:42 PM

Get-PhysicalDisk options

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Disk storage, Powershell

These are the Get-PhysicalDisk options for identifying the disk you want -UniqueId <string> -ObjectId <string> -FriendlyName <string> -InputObject <CimInstance#MSFT_PhysicalDisk> -StorageSubsystem <CimInstance#MSFT_StorageSubsystem> -StorageEnclosure...


May 30, 2017  1:55 PM

String casing

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

There are times when you may want to change string casing. You have a couple of options. There are a couple of methods on the string class that you can use to modify the case of a string.

PS> 'aaa'.ToUpper()
AAA

PS> 'AAA'.ToLower()
aaa
Alternatively you can use the...


May 29, 2017  12:51 PM

Build a better pull server

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Desired State Configuration, Powershell

DSC functions in 2 modes – push (most basic) and pull. Creating a pull server is a non-trivial task and the out-of-the-box pull server has some issues. Some of the folks at powershell.org have decided its time to build a better pull server. There’s a project on github that supplies the code...


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: