41
u/delliott8990 Jun 01 '19
Hahaha, so true and I'm guilty of it myself in numerous posh scripts. I ended up making a function to grab ss64.com examples via invoke-webrequest.
11
u/Pandapokeman Jun 01 '19
Please share
10
u/delliott8990 Jun 02 '19 edited Jun 02 '19
Sorry for the formatting, not sure what the markdown tag for code is off the top of my head..
[CmdletBinding()]
param
(
[string]$commandEntry
)
Function Get-SS64Help
{
[CmdletBinding()]
param
(
[string]$commandEntry
)
if($verbose)
{
$verbosePreference = SilentlyContinue
}
$baseUrl = "https://ss64.com/ps"
$fullUrl = "$baseUrl/$commandEntry.html"
Write-Verbose "$fullUrl"
try
{
$resp = Invoke-WebRequest -Uri $fullUrl -ErrorAction Stop
Write-Verbose $resp
}
catch
{
Write-Host "Invoke-WebRequest: Error contacting $fullUrl"
Write-Verbose $_
}
$overview = $resp.AllElements | Where {$_.TagName -eq "pre"}
$syntax = $overview.innerText
$examplesOverview = $resp.AllElements | Where {$_.TagName -eq "p" -and $_.Class -match "code"}
$examples = $examplesOverview.innerText
$returnObj = @{
Syntax = $syntax
Examples = $examples
}
return $returnObj
}
Get-SS64Help -commandEntry $commandEntry
To use
c:/path/to/get-ss64help.ps1 -commandEntry "get-acl"7
u/nascentt Aug 12 '19 edited Aug 13 '19
I love this script it deserves more recognition.
I put the code in a code block, added a line to output the data rather than the object, and converted url to lowercase so it always returns.
[CmdletBinding()] param ( [string]$commandEntry ) Function Get-SS64Help { [CmdletBinding()] param ( [string]$commandEntry ) if($verbose) { $verbosePreference = SilentlyContinue } $baseUrl = "https://ss64.com/ps" $commandEntry = ($commandEntry).ToLower() $fullUrl = "$baseUrl/$commandEntry.html" Write-Verbose "$fullUrl" try { $resp = Invoke-WebRequest -Uri $fullUrl -ErrorAction Stop Write-Verbose $resp } catch { Write-Host "Invoke-WebRequest: Error contacting $fullUrl" Write-Verbose $_ } $overview = $resp.AllElements | Where {$_.TagName -eq "pre"} $syntax = $overview.innerText $examplesOverview = $resp.AllElements | Where {$_.TagName -eq "p" -and $_.Class -match "code"} $examples = $examplesOverview.innerText $returnObj = @{ Syntax = $syntax Examples = $examples } return $returnObj } $result = Get-SS64Help -commandEntry $commandEntry $result.Syntax "" $result.Examples #To use `.\get-ss64help.ps1 -commandEntry "get-acl"`2
5
u/Lee_Dailey [grin] Jun 02 '19
howdy delliott8990,
reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...
[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the resultlooks like this. kinda handy, that. [grin]
[on New.Reddit.com, use theInline Codebutton. it's4th5th from the lefthidden in the...""more" menu & looks like</>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!][1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use theCode Blockbutton. it's11th12th one & is just to the left ofhidden in the..."more" menu.]
one leading line with ONLY 4 spaces
prefix each code line with 4 spaces
one trailing line with ONLY 4 spaces
that will give you something like this ...
- one leading line with ONLY 4 spaces
- prefix each code line with 4 spaces
- one trailing line with ONLY 4 spaces
the easiest way to get that is ...
add the leading line with only 4 spaces
copy the code to the ISE [or your fave editor]
select the code
tap TAB to indent four spaces
re-select the code [not really needed, but it's my habit]
paste the code into the reddit text box
add the trailing line with only 4 spaces
not complicated, but it is finicky. [grin]
take care,
lee3
u/delliott8990 Jun 02 '19
I'm working on finding it but admittedly, it's been a while. It really wasn't anything special. I basically just grabbed the content from the web request and ran it through a series of regexs to filter out most of the HTML tags and some of the unnecessary stuff to make it "readable". I'll dm you if I can track it down.
1
9
8
4
u/schmeckendeugler Jun 02 '19
The opposite being, reading the msdn article explaining what methods and classes are part of the object.. you know your e desperate when you've reached that page.
3
u/1RedOne Jun 02 '19
That's when you know Powershell has tricked you into becoming a developer.
Happened to me I started out as just the PowerShell guy and now I'm writing asp net mvcs. Tricky tricky!
1
Jun 02 '19
Maybe I'm nuts; but, the MSDN page for a class is one of the first places I go when I am trying to figure something out. I'm also guilty of spending an inordinate amount of time on pinvoke.net as well. Though, I seem to have a bad habit of saying, "I want to automate X", only to find out that X involves having to delve into the Win32 API.
1
3
3
u/get-postanote Jun 01 '19
Or just the examples, wihout tall the explanation, well, as long as yu odon' tneed the explanations. ;-}
Examples for my snippet and profile for easy access file I give to my students.
Function Get-HelpExamples
{
[CmdletBinding()]
[Alias('ghe')]
Param
(
[string]$CmdletName = (
Get-Command -Name '*' |
Out-GridView -PassThru -Title 'Select a cmdlet to see examples'
)
)
If ((Get-Help -Name $CmdletName).Examples)
{
(((Get-Help -Name $CmdletName).Examples |
Out-String -Stream) -match '.*\\>|C:\\PS>') -replace '.*\\>|C:\\PS>' |
Out-GridView -Title 'Select a sample to use' -PassThru
}
Else {Write-Warning -Message "The were no help examples discovered"}
}
ghe -CmdletName Get-ChildItem
# Results
Get-ChildItem
Get-Childitem -System -File -Recurse
Get-ChildItem -Attributes !Directory,!Directory+Hidden
dir -att !d,!d+h
dir -ad
Get-ChildItem -File -Attributes !ReadOnly -path C:\ps-test
get-childitem . -include *.txt -recurse -force
get-childitem c:\windows\logs\* -include *.txt -exclude A*
get-childitem -nameOr search help by keyword.
function Search-HelpByKeyword
{
[CmdletBinding()]
[Alias('shbk')]
Param
(
[string]$Cmdlet = (Read-Host -Prompt 'Enter a cmdlet, function, script name to search for or use "*" to seach all help files. The all searhc will generate some errors, that can be ignored.'),
[string[]]$SearchString
)
Get-Help $Cmdlet |
Out-String –Stream |
Select-String -Pattern $SearchString
}
shbk -Cmdlet Get-WmiObject -SearchString 'computer'
# Results
[-Authority <String>] [-ComputerName <String[]>] [-Credential <PSCredential>] [-DirectRead]
[-ComputerName <String[]>] [-Credential <PSCredential>] [-EnableAllPrivileges] [-Impersonation
PacketIntegrity | PacketPrivacy | Unchanged}] [-Authority <String>] [-ComputerName <String[]>]
information about the available WMI classes. To specify a remote computer, use the ComputerName
the ComputerName parameter of the Get-WmiObject cmdlet even if your computer does not meet the
returns has a PSComputerName alias. This makes it easier to include the source computer name in3
u/1RedOne Jun 02 '19
Powershell can't find the help because we wanted to save 4kb and didn't ship it in box, lol oh yeah and if you try to download it while not an admin it will fail unless you use a certain param1
1
1
u/fatherjack9999 Jun 02 '19
if you create a function called Get-Help that has your preferred switch in it and then add that you your profile you can avoid having to specify the parameter. eg:
function Get-Help {
<#
Description
Custom version of Get-Help to avoid having to specify -showwindow every time
Example
get-help gci
This example runs the bespoke Get-Help function from your session and passes in the alias of
Get-ChildItem. With -showwindow specified in the bespoke function you will get the ShowWindow view of the
help for Get-ChildItem.
#>
[cmdletbinding()]
param ([string]$CmdName)
Write-Verbose "Custom Get-Help function is running"
$scrpt = {Microsoft.PowerShell.Core\get-help $CmdName -ShowWindow}
. $scrpt
}It does of course prevent you running the 'stock' Get-Help cmdlet unless you specify the path to that cmdlet as
Microsoft.PowerShell.Core\get-helpUsing this specific path would let you specify alternate parameters if you want to.
Be sure to understand the implications of this before you go changing your profile...
If you do make the change then you will see this sort of result when you run Get-Command *Get-Help*
CommandType Name Version Source
----------- ---- ------- ------
Function Get-Help
Cmdlet Get-Help 3.0.0.0Microsoft.PowerShell.Core
[edit]
This works because there is a hierarchy in the places that PowerShell looks for commands that are issued and the local function provider is checked ahead of the default commands
1
1
u/HowDidFoodGetInHere Apr 09 '24
Really, where I work, with all the GPOs that block module updates, I find it so much faster and easier to Google the cmdlet and go straight to the MS help page. The examples are there, along with everything else you need.
1
-3
u/NowInOz Jun 01 '19
Microsoft: why use a 3 letter command (man) when a 17 letter one will do.
5
u/get-postanote Jun 01 '19
Virtually every single cmdlet /parameter has a shorthand / alias for interactive use. They are easily discoverable, as long as you know how.
# Get named aliases Get-Alias | Out-GridView -PassThru -Title 'Available aliases' # Get cmdlet / function parameter aliases (Get-Command Get-ADUser).Parameters.Values | where aliases | select Name, Aliases | Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'Note, I say interactive, not in scripts. Code for those who follow you, aliases, especailly iaonces you create should not be in production scripts. It make the hard to read, troubleshoot and maintain. Especailly if you have spent no time learning and using the to recognize what they are.
Let's see anyone try and read War and Peace in a secretaries shorthand crib notes. ;-}
Well, for those prone to read War and Peace or the help files at all.
2
u/fatherjack9999 Jun 04 '19
Virtually every single cmdlet
(get-command).count
(get-alias).countI get 9419 vs 360 ! Not quite every one !! ;)
4
u/Matty_R Jun 01 '19
Man is an alias for get-help lol. Besides alias' being a thing, I prefer commands having descriptive names. Also, help -full will also show examples.
3
Jun 02 '19
Y'all are haters, this guy is right powershell is super clunky compared to so many things.
2
Jun 02 '19
PowerShell is pretty verbose in getting things done. The other side of that is scripts tend to be pretty self-documenting because of it.
2
u/poshftw Jun 03 '19
Linux: why have a meaningful command name when you can name it after program authors?
Also Linux: oh, by the way, you want to see the list of your Directories and Files? Use obscure command from decades ago, when there was no files and directories at all.
1
0
Jun 01 '19
[deleted]
8
u/AJaxStudy Jun 01 '19 edited Oct 26 '25
vase glorious screw crown bright continue dinosaurs like teeny history
This post was mass deleted and anonymized with Redact
6
1
6
u/nin_zz Jun 01 '19
get-help -online :o
5
u/MrWinks Jun 02 '19
No way; update-help and then get-help -showwindow; it’s way more useful.
3
u/Quadman Jun 02 '19
"Update-Help" | out-file $Profile -append
2
u/MrWinks Jun 02 '19
$Profile? As in, Env:userprofile? (Forgot syntax, on mobile)
2
u/Quadman Jun 02 '19
I too am on mobile but if i recall correctly you can use either.
1
2
u/Lee_Dailey [grin] Jun 03 '19
howdy MrWinks,
i have no idea why anyone would want to add the output of
Update-Helpto the current profile ... but the$Profilestuff is about the current powershell profile, not the windows user profile. take a look at ...Get-Help about_Profiles... for what they are about.
take care,
lee2
u/MrWinks Jun 03 '19
Thanks, Lee. I tried it easier and it points to a specific ps1, which only heightened my confusion haha.
1
u/Lee_Dailey [grin] Jun 03 '19
howdy MrWinks,
you are welcome! [grin]
the only things in my profile[s] are a change location to set the working dir to my preferred default & the chocolatey stuff.
take care,
lee5
u/MrWinks Jun 01 '19
Hell no. Get-Help -ShowWindow. It’s like the “open link in a new tab” of PowerShell.
2
u/[deleted] Jun 03 '19
Ahem
man -dis the correct way