Author Posts

October 4, 2017 at 1:36 am

I wanted to try this sample code from "Learn Powershell Scripting in a Month of Lunches" but get an error re: the variable $cs

function Get-DiskInfo {
 foreach ($domain in (Get-ADForest).domains) {
   $hosts = Get-ADDomainController -filter * -server $domain |
   Sort-Object -Prop hostname
   ForEach ($host in $hosts) {
    $cs = Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName
[CA]$host
    $props = @{'ComputerName' = $host
               'DomainController' = $host
               'Manufacturer' = $cs.manufacturer
               'Model' = $cs.model
               'TotalPhysicalMemory(GB)'=$cs.totalphysicalmemory / 1GB}
     New-Object -Type PSObject -Prop $props
    } #foreach $host
  } #foreach $domain
} #function

Error: "Missing an argument for parameter 'ComputerName'" Shouldn't it be -ComputerName $host ?

yet, If I do that (remove [CA]) I get error: "Cannot overwrite variable host becuase it is read-only or constant"

I am considering purchasing this book but just wanted to test some of its scripts in my lab environment

October 4, 2017 at 3:25 am

Ugh. The CA thing is a typesetting mark; I don't know why that's in the sample code. If you can tell me the listing number I'll go grab the original for you. I think you've just got typesetting crap messing you up. $host itself MIGHT be a problem on certain systems, which is a brand new thing, but you could just replace that variable globally with something else. The original code runs fine on my computer.

October 4, 2017 at 3:53 am

I found it here: https://livebook.manning.com/#!/book/learn-powershell-scripting-in-a-month-of-lunches/chapter-17/v-3/65
17.3.3 Our Take

...but it seems to be all over, starting here as well: 17.2.1 The walkthrough (various tables/examples)

I'm hoping not to have to troubleshoot the code though too much which sort of breaks my focus from the lesson at hand. Can these be fixed at least in the online version?

note: I see I can remove the [CA] then move that line back up to the end of the previous line in order to make it work (no pipe or escape character of course there) but if I have to do that for numerous examples I think I'll pass on this particular purchase at this time. I had a 50% coupon but it expires tonight at midnight.

October 4, 2017 at 1:22 pm

Yeah, we have listings without all that mess. I'll have Jeff resend it to them.

October 4, 2017 at 1:49 pm

OK, Jeff's going to get them an updated downloadable. Might take a day – he wants to run through and make sure there aren't more of these lingering in them. Sorry about the confusion.

I will note, though, that the "Scripting" MoL isn't really the "starting point" book. You'll want to get the other one as a starting point, if you've not already done so, unless you basically already know everything in it.

The [CA], incidentally, is a typesetting mark that tells them to put in a line-wrap character in the book. It'll always appear in all of the manuscript files – e.g., PDF, etc. The actual sample code ZIP shouldn't have those, though, and that's what Jeff's gonna fix and get to them.

October 4, 2017 at 2:02 pm

You know, I want to clarify something – are you just copying and pasting code from the live book manuscript, or did you actually download the sample code?

If you're copying and pasting, you're always going to run into this. We have to go through contortions to make code fit into a printed page, and the manuscript reflects that. That's why the download is provided – it's the un-contorted code. I know that's provided to everyone who purchases the book, and Jeff's gone through it and isn't seeing any of the typesetting stuff.

October 4, 2017 at 4:58 pm

I've downloaded pdf and eBook for my purchased stuff but when I saw "LiveBook" under books I was considering purchasing, I thought that best for testing the scripts that had "COPY" under them. That's where the trouble started 🙂

October 4, 2017 at 5:00 pm

the "Scripting" MoL isn't really the "starting point" book. You'll want to get the other one as a starting point

  • What do you mean, "the other one"? I have own a few MOL books.