PowerShell - I can't get "get-help" to work within a script

At the PowerShell command prompt, "get-help get-WindowsFeature", it works.  I can see the output.

But when I place that same command in a PowerShell script, I get an error.

Does the get-help command need an absolute path when run from within a script?

I'm using Windows Server 2012 R2.

Please see attached.

Thanks
problem.pdf
Dwight BaerStudentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
In the text file, you have a bunch of spaces at the end of "Get-WindowsFeature". Try
$commands = Get-Content PSCommands2.txt 
Foreach ($i in $commands) {
	Get-Help $i.Trim()
	Write-output "This is $($i.Trim())"
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dwight BaerStudentAuthor Commented:
Works great!  Thanks so much.
0
Dwight BaerStudentAuthor Commented:
For future reference:
1.  get-command | select object-name > PSCommands.txt
2.  write-output " " > manual.txt   # empty the "manual" file for this iteration
3.  $commands = Get-Content PSCommands.txt  # Load the $commands variable with the contents of PSCommands.txt, i.e. the list of all the PowerShell commandlets that are available with this particular installation / configuration of Windows Server 2012
4.  # Here is the loop:
foreach ($i in $commands) {
write-output "Working on $i"  # Progress indicator - this will take a few minutes to complete
write-output ">>>>>> $i <<<<<" >> manual.txt  # So I can quickly navigate to the command afterwards, I'll label the beginning of each command
get-help $i.Trim() -Full >> manual.txt   # This is the heart of it - use get-help (with "Trim" to remove the white space)
                                                                    # for each commandlet, and append it to manual.txt
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.