The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

pb4072 (3) [Avatar] Offline
#1
Hi,

I'm doing a little seminar on PowerShell at my company tomorrow. I've had Bruce's book for a couple of months now. It's a great book. I'm learning a lot. But, I wanted to show off some of the various interfaces that Powershell can talk through, to WMI, to ActiveDirectory, to COM, etc., etc., Anyway, when trying the following commands, I just get errors.
Get-SoftwareFeatures prodpeter (my PC)
Get-SoftwareFeatures not recognized as a cmdlet.
Get-DomainInfo prodpeter (my PC)
Get-DomainInfo not recognized as a cmdlet
Get-HotFixes
Get-Hotfixes not recognized as a cmdlet
Thanks,
Peter
dmerida (13) [Avatar] Offline
#2
Re: WMI and Active Directory stuff. How come I can't access any of it with PS?
Hi Peter,

The cmdlets you are referencing are sample scripts available in Bruce's book. On page 500, you will find these sample scripts. If you have not already created and saved these scripts as .ps1 files, PowerShell can not run them because technically they do not exist.

Once you have saved these scripts to a file location, run them from PowerShell with the following syntax:

PS > c:filefolder/script.ps1

or navigate to the folder location in powershell and do:

PS c:filefolder> ./script.ps1

Also keep in mind that you can still access WMI and COM without the use of scripts. Try some of these if you just want to show what is accessible:

WMI:
Get-Wmiobject win32_physicalmemory -computer prodpeter
Get-Wmiobject win32_logicaldisk -computer some server you have access to

COM:
$net = new-object -com "WScript.Network"
$net.UserName
$net.ComputerName

Finally, here is a WMI class library, courtesy of MSDN.
http://msdn.microsoft.com/en-us/library/aa394084(VS.85).aspx

Cheers!
pb4072 (3) [Avatar] Offline
#3
Re: WMI and Active Directory stuff. How come I can't access any of it with
Thanks a lot for your response.
So, I carefully type, checked and re-checked, the scripts on page 500-501. I named them "Get-DomainInfo.ps1" and "Get-SoftwareFeatures.ps1" in my PS scripts foldeer. But, when I try to run them in PS, it says there's no such thing! "not recognized as a cmdlet", etc., etc.
dmerida (13) [Avatar] Offline
#4
Re: WMI and Active Directory stuff. How come I can't access any of it with
When you try to run your scripts, have you already navigated to where they are saved to? Let's say for example you save your PS scripts to the location C:scripts, and you fire up PS, do you:

Use set-location to navigate to the script folder?

PS > set-location c:scripts
PS C:scripts>./get-softwarefeatures.ps1

Or do you try to run the script right after you start PS?

PS > c:scripts/get-softwarefeatures.ps1
pb4072 (3) [Avatar] Offline
#5
Re: WMI and Active Directory stuff. How come I can't access any of it with
I saved these two scripts in my default directory that PS goes to when it fires up. So, I'm in that directory at the time I'm trying to execute them. I tried doing a "set-location," like you suggest below, but, it still behaves like it doesn't know what I'm asking.
dmerida (13) [Avatar] Offline
#6
Re: WMI and Active Directory stuff. How come I can't access any of it with
I'm not sure what's happening then. I keep my scripts in a location similar to c:scripts. When I start powershell, it's default directory is z:. So what I do:

PS Z:>set-location c:scripts
PS C:scripts>./get-softwarefeatures.ps1

and that runs fine, or I do:

PS Z:>c:scripts/get-softwarefeatures.ps1

and that runs fine too. This is using the script as is from page 501.

If the error you're receiving has to do with execution policy, try setting your execution policy to something other than restricted.

PS >set-executionpolicy remotesigned

Hopefully this helps.