Is anybody having this Powershell "Update-Help" command, issue? - powershell

I am trying to download and install Help files for all the commands but it won't work. I am using Powershell 7.1.1 inside the Windows Terminal.
Update-Help: Failed to update Help for the module(s) 'ConfigDefender, PSReadline' with UI culture(s) {en-US} : One or more errors occurred. (Response status code does not indicate success: 404 (The specified blob does not exist.).).
English-US help content is available and can be installed using: Update-Help -UICulture en-US.
This is exactly what the out-put looks like

Solved, thanks to another post I've found on stackoverflow.
According to Microsoft, the below command should work in case of errors regarding the cmdlet: Update-Help.
Update-Help -Verbose -Force -ErrorAction SilentlyContinue

The issue is the capitalization of PSReadline, which changed to PSReadLine with PowerShell 6.
Fix is easy:
Close all PowerShell windows
From TaskMgr make sure to kill any remaining PowerShell processes.
Open Admin Cmd prompt (not PowerShell) and run the following:
ren "C:\Program Files\WindowsPowerShell\Modules\PSReadline" PSReadLine
ren "%APPDATA%\Microsoft\Windows\PowerShell\PSReadline" PSReadLine
That's it. Now you can close the Cmd prompt window, open a PowerShell window and do a normal Update-Help.
See this blog for some additional context:
https://devblogs.microsoft.com/powershell/updating-help-for-the-psreadline-module-in-windows-powershell-5-1/

Related

Why does Chocolatey hang when using Powershell ISE without the `-y` switch?

When using PowerShell ISE with Chocolatey to install applications, if I forget the -y switch, it hangs waiting on some sort of "confirmation" that's not popping up anywhere?
I have to Ctrl+Alt+Del to kill PowerShell ISE and Chocolatey and it leaves things in half-way state.
This is what it looks like below:
In addition to the comments to the OP above, regarding PowerShell ISE not supporting (most) interactive console applications...
It is worth remembering that the REPL window in PowerShell_ISE.exe is not just some sort of docked PowerShell.exe console. Most of the time the user experience is the same, but this hides a number of differences:
https://blogs.msdn.microsoft.com/powershell/2009/04/17/differences-between-the-ise-and-powershell-console/
Both these executables are host applications that run a PowerShell runspace (engine). You can even write your own application that "hosts" PowerShell. It is the host application that determines the user experience.
PowerShell.org: The Shell vs The host
Spiceworks.com: The Shell vs The Host
Writing a Windows PowerShell Host
And finally, for the most curious:
How PowerShell works
I think I wrote this answer more for my own benefit; it's a useful refresher for me as I get asked this by colleagues every now and again...
It's simply because PoSH ISE is not a thing to use for user interactive .exe commands.
If you .exe or whatever expects a response, when in the ISE you have to provide it.
You can easily prove this is not a Chocolatey thing by trying any other .exe that kicks out interactive stuff. For example, just type:
nslookup in the script pane and F8 to run it, or type it in the console pane and hit enter
Either way, the console will just hang, waiting for a interactive response that you cannot provide.
You can still use interactive commands like nslookup in the PoSH ISE, but you have to provide all parameters. For example:
nslookup microsoft.com
nslookup -type=mx microsoft.com
nslookup -q=soa microsoft.com
PS 5.1 even kicks out an error message now.
nslookup
Cannot start "nslookup". Interactive console applications are not supported.
To run the application, use the Start-Process cmdlet or use "Start PowerShell.exe" from the File menu.
To view/modify the list of blocked console applications, use $psUnsupportedConsoleApplications, or consult online help.
At line:0 char:0
You can easily shell out to the PowerShell console host temporarily this way.
Here is a function I have in my profile for such efforts.
Function Start-ConsoleCommand
{
[CmdletBinding()]
[Alias('scc')]
Param
(
[string]$ConsoleCommand,
[switch]$PoSHCore
)
If ($PoSHCore)
{Start-Process pwsh -ArgumentList "-NoExit","-Command &{ $ConsoleCommand }" -Wait}
Else
{Start-Process powershell -ArgumentList "-NoExit","-Command &{ $ConsoleCommand }" -Wait}
}
So, just type
scc -ConsoleCommand choco install winmerge
It'll pop the console host and stay open until you close it.
Update
As per request of - Alex Kwitny
PoSHGet default has only two repositories,
nuget
PSGallery
but you can add your own or another.
You use the below cmdlets to make this happen.
I have not had to use Chocolatey in a while, but taking a quick look and my archives, the below is what I used
Set up chocolatey repository
Find-Module
Get-Module
Find-Package
Get-Package
Get-PackageProvider
Get-PackageSource
Get-PackageSource -Provider chocolatey
Register-PackageSource -Name chocolatey -Provider Chocolatey -Trusted -Location http://chocolatey.org/api/v2/ -Verbose
Find-Module
Get-Module
Find-Package
Get-Package

Post Build PowerShell Script does not include installed modules

I am calling the below script in my post build configurations:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile
-ExecutionPolicy RemoteSigned -file "\Sclddev8\tfs\Scripts\slack-notice.ps1" -Verb RunAs;
However, I keep getting this error:
Send-SlackMessage : The term 'Send-SlackMessage' is not recognized as the name
But I have installed this module in my environment and if I open a PowerShell console or run the file outside of this build process, works without issue.
When you install a Powershell module, you are technically importing the module from your profile every time you open a new Powershell window. By running Powershell with the "-NoProfile" switch, you're preventing the module from being imported (even though it's "installed" and the files are present).
What may be your best option, if you want to keep the "-NoProfile" switch active, is to have a line at the top of your script to import the module before continuing. If you're using Warren Frame's "PSSlack" module, the command you need is:
> Import-Module PSSlack
I hit the same issue.
What helped was... copying the folder into C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules.
Yup, it makes a difference.

Module returns different result from the script version [Test-Path]

introduction
I've written my first PowerShell script aimed for retrieving detailed information from a Windows Setup ISO file. Once the basic features achieved, I've started to convert the ps1 script into a psm1 module. I hoped the result would be the module just work like the script but I'm facing issue I'm not able to solve.
You can download my work here, script version and module (roughly translated to English from French).
I successfully installed the module in PSModulePath in:
[Environment]::GetFolderPath("mydocuments")\WindowsPowerShell\Modules
Command usage is very simple. You call it like that:
WinIsoInfo [[-Path] <String>] [<CommonParameters>]
Help is provided by module: man WinIsoInfo
Usage Example:
WinIsoInfo -Path "E:\Win 10\Installation\ISO\Windows 10 x64 fr.iso"
The ps1 script version is the exact same code as the psm1 module but there are commands examples at the end of the file that you can un-comment and edit before running the script.
Current Status
All the tests are and need to be run as admin, in console or PowerShell ISE.
The ps1 script works as expected but the psm1 module doesn't produce the same result.
At line 108 of the code, there is a Test-Path in a Switch statement:
{(Test-Path "$wimPath\sources\install.wim") -or (Test-Path "$wimPath\sources\install.esd")}
In the ps1 script, this Test-Path return True and user get the expected info.
But in the psm1, it seems to return False since Switch statement jump to the next test after this one. So at the end the user gets that the ISO doesn't contain windows setup. I can assure that the Test-Path should return True because I manually checked it while the function was paused by breakpoints.
Hint and lead
There are 2 cases where I manage to get the module work as expected. But only using in PowerShell ISE, NOT in console.
Using Automatic Variable $? in console pane while debugging module
Step to reproduce:
PowerShell ISE is not running.
Open PowerShell ISE as admin.
In console pane, run import-module Get-WinIsoInfo -Force -Global -Verbose or import-module -path X:\Path\To\Modules\Get-WinIsoInfo -Force -Global -Verbose
In console pane, run WinIsoInfo -Path "X:\path\to\AnyWindowsSetup.iso"
In my case, at this point, the command returns there is no Windows Setup in ISO file.
Now open the Get-WinIsoInfo.psm1 and put a breakpoints anywhere between line 90-108.
do step 4 again
While the script is paused at breakpoints, run $? in the console pane then press F10 then F5
And "voilĂ  !" the module return the expected result and will keep working but only during PowerShell ISE session and inside PowerShell ISE. Command run in console still won't work. And the next time I run PowerShell ISE, the module won't find the setup image path again.
Previously run the ps1 script version in PowerShell ISE
Step to reproduce:
PowerShell ISE is not running.
Open PowerShell ISE as admin.
In console pane, run import-module Get-WinIsoInfo -Force -Global -Verbose or import-module -path X:\Path\To\Modules\Get-WinIsoInfo -Force -Global -Verbose
In console pane, run WinIsoInfo -Path "X:\path\to\AnyWindowsSetup.iso"
In my case, at this point, the command returns there is no Windows Setup in ISO file.
Now open the Get-WinIsoInfo.ps1 script, edit a valid command at the end of the code then press F5 to run it.
Note: Since the command in script has the same name as the module previously imported, at this point I don't know if the triggered function is the one from the ps1 script or the one from the module. Tell me if you know.
The script returns the expected result as Windows Setup info.
Close the ps1 file (it is no longer needed in PowerShell ISE for the next to work)
do step 4 again
And "voilĂ  !" the module return the expected result and will keep working but only during PowerShell ISE session and inside PowerShell ISE. Command run in console still won't work. And the next time I run PowerShell ISE, the module won't find the setup image path again.
Conclusion
After the Hint and lead tests, I found out that they were some differences from modules imported in session before and after success. These key modules loaded by PowerShell ISE are Storage and Microsoft.WSMan.Management. I thought I found the solution and added this line to manifest:
RequiredModules = #("Storage";"Microsoft.PowerShell.Management";"Microsoft.PowerShell.Security";"Microsoft.PowerShell.Utility";"Microsoft.WSMan.Management")
I added all the modules that was present after the module works as expected, just to be sure.
I did the same for assemblies but 2 of them could not be imported: Microsoft.Management.Infrastructure.UserFilteredExceptionHandling and Microsoft.Management.Infrastructure.resources
Resulting in this new manifest line:
RequiredAssemblies = #("Microsoft.Management.Infrastructure.Native";"Microsoft.WSMan.Runtime";"System.Security")
Unfortunately, it seems it is not enough to solve the issue.
Maybe other things has to be imported or it's a wrong lead.
I really hope you could reproduce the bug or at least I hope the Hint and lead section will lead you to find the cause and a solution. I'm too novice to understand why this happens on my system.
My setup uses PowerShell v5.0 with Win 8.1 Pro.

Get-Help cannot find the Help files for ServiceFabric module

I installed the Azure Service Fabric SDK and I wanted to get some help information on some of the commands:
Get-Help Connect-ServiceFabricCluster
It returns the following output under remarks:
REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
I ran Update-Help -Module ServiceFabric in an administrator window and I still get this error.
How can I get the help to work for the ServiceFabric powershell commands?
I just ran Update-Help successfully from an admin window, are you still seeing this problem? You could try running Update-Help -Module ServiceFabric -Force to force update.
Sounds like an issues with PowerShell Update-Help. This post provides a little more info and a workaround.
I had a similar issue with core commands, i.e. I couldn't get detailed help for Get-Command.
In my case it helped specifying the locale to en-US when running Update-Help as there seems to be a Problem with the fallback to en-US when no other help files can be found.
Command it worked with:
Update-Help -UICulture en-US
See also:
https://github.com/PowerShell/PowerShell/issues/6217

how to edit a file in powershell remoting session (powershell)

I am connecting to another computer using powershell remoting, really nice. can do lots, but how do I edit a file?
PS C:\Users\guutlee> Enter-PSSession -ComputerName appprod
[appprod]: PS C:\Users\guutlee\Documents> cd \myapp
[appprod]: PS C:\myapp>
what can I do to open a file editor on a file on the remote machine?
[appprod]: PS C:\myapp> edit app.config
so edit "filename" just seems to hang, from powershell.exe or from powershell_ise.exe
The only thing I can think of is back out of the pssession and "start \webprod\c$\inetpub\myapp\web.config", which would open visual studio.
[appprod]: PS C:\myapp> exit
PS C:\Users\guutlee> start \agobuild\c$\myapp\app.config
PS C:\Users\guutlee> Enter-PSSession -ComputerName appprod
[appprod]: PS C:\Users\guutlee\Documents> cd \myapp
[appprod]: PS C:\myapp> myapp.exe
Of course with this I have to re-find the file, hope that the c$ share is available and accessible, and the reconnect my pssession and re-find my working directory when I want to go on. It doesn't seem very elegant.
I could maybe wrap this is a function, but having a hard time wrapping my head around that..
so how do I conveniently edit a file with a remote pssession?
EDIT
kbrimington's post got me thinking me about the -X option to ssh. probably would be an awesome thing for powershell sessions to be able to forward windowed apps back to the original windowing environment...
but still I'd be happy just to edit the file.
EDIT
tests using vi, emacs, cmd and edit
PS C:\Users\Meredith> Enter-PSSession -ComputerName appprod
[appprod]: PS C:\Users\guutlee\Documents> C:\vim\vim72\vim filename.txt
[appprod]: PS C:\Users\guutlee\Documents> C:\emacs-23.2\bin\emacs.exe -nw filename.txt
emacs.exe : emacs: standard input is not a tty
+ CategoryInfo \: NotSpecified: (emacs: standard input is not a tty:String) [], RemoteException
+ FullyQualifiedErrorId \: NativeCommandError
[appprod]: PS C:\Users\guutlee\Documents> cmd
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\guutlee\Documents>
[appprod]: PS C:\Users\guutlee\Documents> edit filename.txt
vi and edit hang (Control-C to get a prompt back)
cmd runs, producing a prompt, but immediately exits back to the powershell prompt
emacs produces the error (standard input is not a tty)
EDIT
Jered suggests pulling the file back locally to edit. I embellished his answer to copying using pssessions rather than UNCs (perhaps this is what he intended)
PS C:\Users\Meredith> Invoke-Command -Session $ps -ScriptBlock {get-content c:/inetpub/myapp/web.config} > web.config
edit web config
PS C:\Users\Meredith> get-content web.config | Invoke-Command -Session $ps -ScriptBlock {set-content c:/inetpub/myapp/web.config}
Potentially we could run the invoke-commands in either direction, local to remote or remote back to local.
If you are using Powershell 5, you can use command called PSEdit. It only works from ISE.
So first, open PowerShell ISE
Then open remote session to the remote computer using Enter-PSSession
Then edit the file using PsEdit 'filename'
The remote file will be opened in a new tab in your (local) ISE window.
Actually I found this answer from the comments section of this SO question , but I think it will be helpful for others if I post it as answer here.
Can you not pull the file locally, edit it and post it? I know this is tedious and not elegant but it seems editors are presently having issue with remote sessions.
E.g.,
Get-Content REMOTE\Filename.txt > LOCAL\Filename.txt
Make your changes locally and then
Set-Content -path REMOTE\Filename.txt -value (get-content LOCAL\Filename.txt)
EDIT
Also if you are only replacing certain instances you can do this pretty easily.
E.g.,
Get-Content REMOTE\Filename.txt | foreach-object { $_ -replace "OLD", "NEW" } | Set-Content REMOTE\Filename.txt
After much digging around, I found something that seems relevant in the powershell help documentation. At the powershell prompt, type:
help about_remote_troubleshooting
At the very end of the help file that is displayed, there is a section entitled 'TROUBLESHOOTING UNRESPONSIVE BEHAVIOUR', which states:
TROUBLESHOOTING UNRESPONSIVE BEHAVIOR
This section discusses remoting problems that prevent a command from
completing and prevent or delay the return of the Windows PowerShell
prompt.
HOW TO INTERRUPT A COMMAND
Some native Windows programs, such as programs with a user interface,
console applications that prompt for input, and console
applications that use the Win32 console API, do not work
correctly in the Windows PowerShell remote host.
When you use these programs, you might see unexpected behavior, such
as no output, partial output, or a remote command that does not
complete. To end an unresponsive program, type CTRL + C. To view any
errors that might have been reported, type "$error" in the
local host and the remote session.
Thus it would seem even non-GUI console applications such as VIM won't work unfortunately. Anyone
care to shed a little light on why this might be the case and/or whether it can be worked
around? I would REALLY love it if I could use vim over powershell remoting.
First, create a temp folder on the local machine (LOCALTEMPFOLDER). Then, use the following function:
function vimrem {param([parameter(position=0,mandatory=$true)][string]$Session, [parameter(position=1,mandatory=$true)][string]$Path)
$TempFile = split-path -path $Path -leaf
copy-item -fromsession $Session -path $Path -destination LOCALTEMPFOLDER\$TempFile
vim $LOCALTEMPFOLDER\$TempFile
copy-item -tosession $Session -path LOCALTEMPFOLDER\$TempFile -destination $Path
remove-item -path LOCALTEMPFOLDER\$TempFile
}
This should work, but you will have leave an interactive session before using this function.
PowerShell_ISE.exe \\REMOTE\...\File.txt
will load and edit the file directly and save it back to the remote computer in one step and, since its command line, easy to build functions using it. Doesn't get around sharing problems, but the easiest way I've found.
Try it out using a console-based editor such as VI or Emacs. As in my comment, I think the problem is that the edit command is bound to a windowed application which, in turn, is not virtualized across a remote session.
I try all the above suggestion and even other microsoft related solution but none works the way you and I want --"full interactive and responsive shell"--. If you really want to have the ssh experience that unix users have from the beggining of time i recomend you install an ssh server. I personally use freesshd, you can find it here http://www.freesshd.com and instructions of how to configure it here http://www.windowsnetworking.com/articles_tutorials/install-SSH-Server-Windows-Server-2008.html. After you make all that it says in the instructions you only need to use any ssh client app to connect to your computer and use powershell full interactive. Vim, edit, emacs or whatever you use to edit a file is going to work without any problem.
i encourage you to not waste your time with psremoting, telnet, winrs, psexec, trying to achieve what a real interactive shell provide (i already lost it, T_T). Try that ssh server an see for your self.
Inspired by the answer provided by #chenz, this can also be done using Visual Studio Code when inside the Powershell Integrated Shell. I tried this with Powershell 7 over SSH remoting, but should also work with WinRM remoting as well.
Enter-Session ...
[RemoteSystem] PS> psedit service.log
The filename will follow this pattern:
C:\users\dev\appdata\local\temp\2\pses-15960\remotefiles\1702137071\winboxname\service.log
I got nano to work easily over SSH to PowerShell. It's available in Chocolatey so you can just do...
choco install nano -y
Then you can just do...
nano filename
I've been looking into this quite thoroughly given the limitations of PSRemoting and the possible work arounds or solutions.
Console editors do not work as they are native (exe) commands and are character based. (I'm wondering if cmd over ssh works with these) It needs to be a cmdlet to properly interact with the console host over a psremote session.
A PSRemote session is line based. You edit the line locally push enter and then it is sent to the remote end, the command is executed and the result returned. So it does support line interactivity but not character interactivity.
Given all these limitations, GNU's ed appears to be a perfect fit. I'm surprised that no one has looked at implementing it as a cmdlet.
I decided to investigate this further, I checked that the powershell cmdlet read-host works and then the C# equivalent PSHostUserInterface.ReadLine() work over a PSRemote session and they do, which is all that is needed to make a working line editor.
So here's what I've done so far. I could probably use some help on the more exotic regex code.
https://github.com/silicontrip/ps-ed
I've used this to edit files via a psremote session. (I wouldn't go editing large source files with it, but for the odd small config file or ps1 script it is perfect.)
Make sure you are familiar with GNU ED before using this cmdlet. It'd be like trying to use VI for the very first time, otherwise.