Custom read-host dialog for PowerShell 2 CTP3 ISE - powershell

Is it possible to hook a custom dialog into the new PowerShell ISE (Integrated Scripting Environment) that replaces the existing .NET WinForms dialog. I am talking about the dialog that the Read-Host cmdlet launches to request for user input.

For example, see this URL:
http://www.microsoft.com/technet/scriptcenter/resources/pstips/feb08/pstip0208.mspx
Drop the full code into Notepad.
Add the first line:
function read-host {
Add the last line:
}
Copy all the contents from Notepad.
Paste it all into your PowerShell console.
Now, if you call read-host, you're going to see a new Windows Form.
Now, if I open other windows, it remains on top, but it seems it is not the top-most because I see it over everything else, but still need to click on it to make it active.

What you CAN do is create a custom function that overrides Read-Host, so you're effectively usurping Read-Host and subbing your own functionality.

I don't believe you can, no. You'd need to write your own hosting application. The ISE does have its own object model - I'm asking if what you're after is possible.

Related

Download and Extract Remote Application File from Website

I am pretty new to IT Administration and I think I have a pretty complicated request but I want to know if it is even possible through Intune. I have an application that I want to deploy and I think I would either need to package the application as a Win32 app or via a Powershell Script. I basically would need to download the zip from this website, extract the contents, open the WCX, silently pass through the prompts, and pin the app to the taskbar. Again I am not sure if this is even possible but this would save me a lot of trouble if there was an easy way to do this. Here is the link.
https://kb.tempworks.com/help/how-to-add-an-enterprise-shortcut-to-the-desktop
To download a file, use Invoke-WebRequest with the -OutFile parameter.
To Install a .wcx you use rundll like this:
rundll32.exe 'tsworkspace,WorkspaceSilentSetup' C:\Path\To\The.wcx
(There's a whole wrapper script for that on the old technet script gallery)
It's impossible by design to pin things to users' task bar or start menu programmatically (well, you could script a bunch of hotkey presses and clicks, but don't).

Powershell Credentials Request Window Size

Powershell Noob here.
I have a basic Powershell script that requests user's credentials and then starts MMC programs for remote administration (example: dsa.msc). No issues with the script.
However, I am not happy with the size of the "Windows Powershell Credentials Request" window. I am using Get-Credential "$env:USERDNSDOMAIN\" but our domain name is pretty long.
What I would like:
(Preferred) Have the the domain name gathered in the script ($env:USERDNSDOMAIN) and the when the user is prompted for credentials; the username field will be empty and the user will only need to type their AD username. OR
Have the credentials be collected WITHIN the powershell window so there is enough room
Any assistance is appreciated. Thank you in advance.
You cannot change the default modal dialog/UI in Windows. If you want this control, you can write your own Winfomr/WPF GUI. deploy that for users to execute.
If you have not done this, use this free tool (though WinForm only - for now)...
Online Powershell Form Designer
...for your first effort at GUI design, but read up on GUI design (Winform and WPF) to know what this is about and the other steps you are going to need to do, to get it to do anything.
Youtube -
'PowerShell gui design'
As for your two bullet points. You are halfway there. Just do this:
Get-Credential "$env:USERDNSDOMAIN\$env:USERNAME"

Using a script to search google

I am new to Powershell and after having a few ideas and deciding to tinker around a bit I noticed that I can write a script in Poswershell that will make a search request on a search engine that I specify.
The issue is I am not sure exactly how it works. How is this script able to know how to open my web browser when all I did was specify a string filled with an address?
I have searched up other posts and have not found anything close to what I am asking (I believe).
Here is my source and I will also add an image.
[String]$SearchFor = "bing rewards"
$Query = "http://www.bing.com/search?q=$SearchFor"
Start $Query
Thank you all for your help.
Read help on start-process
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/start-process
If you specify a non-executable file, Start-Process starts the program
that is associated with the file, similar to the Invoke-Item cmdlet.
So if I would have a TXT File in C:\test.txt and run
start-process c:\test.txt
It would open my default application assiociated with that file. On my PC it would open test.txt in notepad.
Hope that makes it clear now.
It simply uses the default application to open URLs on your desktop i.e. your default Internet browser.
Same behavior if you paste the URL (without variables) in your Start > Run box.

Display Message Box to copy code section from it using Powershell script

I am building install.ps1 script for Nuget pacakge and would like to open popup message at the end with some message , i have already achieved by following.
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[Windows.Forms.MessageBox]::Show("Test message ", "Test", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
It will open popup message as per shown in below fig.
Instead of this i would like put some config code here that user can copy from box as per below fig
Please suggest me if anyone has done similar popup box before!
You won't be able to customize Windows.Forms.MessageBox to add what your looking for. In order to do what your looking for you'll need to create a custom form. An easy way of doing this is to use Primal Forms Community Edition which can be found here. You'll need to register for free to reach the download. There's a paid for version to so don't confuse that with the free CE edition. This tool gives you a Visual Studio like forms editor where you can drag and drop controls to a form and save the Powershell script. You'll need to create an event handler for the copy to text to clipboard button. After you saved the code generated by PrimalForms CE you will need to edit it to add the code for the event handlers. An example of how you can set the clip board with Powershell can be found here.
Users can copy the message box text simply by pressing the Ctrl+C key combination.

Without using openfiledialog

I want to send files to my application without using openfiledialog....lost??
OK.
You select a file in my documents, in the SendTo menu, I want my application to be an option,
when you select my application, the file that was selected should be add to the list box in my application, the same way it would do if I was using openfiledialog. But I want my application to run in the background, which means I don't want to use openfiledialog.
Please help??
Using .NET 3.5
I believe this is what you are looking for. You do not need to write any code to get your app in the 'sendTo' menu. Just following the instructions here:
HowToGeek - Customize 'Send To' menu
once the files / references are being passed to your app, you will have to write code to handle those command line args