Link to home
Start Free TrialLog in
Avatar of Dwight Baer
Dwight BaerFlag for Canada

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dwight Baer

ASKER

Works great!  Thanks so much.
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
}