We sometimes see weird name resolution issues on a remote subnet, e.g. where a computer can't be accessed because it seems to have the wrong IP address. 9 times out of 10, this is because the local NetBIOS Master Browser has gone nuts and needs to be taken down. The NetBIOS Master Browser is automatically selected by the computers on the subnet, and it's not always obvious which computer has the role.
This PowerShell one-liner will query the local subnet and report which computers are advertising themselves as a Master Browser.
net view | ? { $_ -match '^\\\\(\S+)' } | % { $matches[1] } | ? { nbtstat -a $_ | sls '__MSBROWSE__' }And here it is broken apart and explained:
net.exe view | # list netbios devices on local network
where-object { $_ -match '^\\\\(\S+)' } | # only use lines formatted like '\\computername'
foreach-object { $matches[1] } | # extract the computer name
where-object { # only return computers which satisfy the following:
nbtstat.exe -a $_ | # ...of all the netbios names that computer advertises...
select-string '__MSBROWSE__' # ...which ones contain '__MSBROWSE__'?
}Command to view who is the master browser?
Workstation is master browser? - Software & Applications - Spiceworks Community
Modern Browser in Powershell GUI
Setting default browser with powershell without 'How do you want to open this?' prompts - Stack Overflow
Videos
Hey guys, i was trying to embed a Browser Window into my Powershell GUI. So, i dont want to use "System.Windows.Forms.WebBrowser' because it uses the internet explorer for various reasons. Is there any way to use like a modern browser?
I really just want a small window inside my Powershell GUI wich showes a Website.
Hopefully someone got a idea. Thanks!
So first, I will say that this is just for fun and not a practical tool. Also, if this is not done correctly, then even as a novelty project it is a very very bad idea.
Create the following registry key:
HKEY_CLASSES_ROOT\powershell\shell\open\command
Set the value of
HKEY_CLASSES_ROOT\powershell\(Default)
to
URL:Powershell Protocol
Create a String with no value:
HKEY_CLASSES_ROOT\powershell\URL Protocol
Create a script for launching scripts that cleans the arguments that it will get with a regex like
'(?<=powershell://).+(?=/)'
Example:
param($Name)
$ScriptName = [Regex]::Matches(
$Name,
'(?<=powershell://).+(?=/)'
).Value -replace '"'
if(Test-path "D:\$ScriptName"){
&"D:\$ScriptName"
}Set the value of
HKEY_CLASSES_ROOT\powershell\shell\open\command\(Default)
to
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -file <PATH TO LAUNCHER SCRIPT> -name '%1''
Then to run a script from a webpage, create a link on it to
powershell://<Name of Script>
For example:
<a href="powershell://Test.ps1">Test Me</a>
When the link is clicked, you will get a confirmation prompt and when you hit OK it should run the script.
Edit: Added some stuff to clean the input in the example script + a better warning. + I like that what is quickly rising to the top of my controversial submissions was awarded gold. Thanks π
Nope, this is not a good idea at all and I can't think of a single-use case where this would be prudent.
I can/see hear your risk management/security folks knocking down your door/desk/cubicle immedialty.
There are better options. PowerShell Web Access for example: (no reg hacking required) and 100% Microsoft supported
Use the Web-based Windows PowerShell Console
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/hh831417(v=ws.11)
Install and Use Windows PowerShell Web Access
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/hh831611(v=ws.11)
PowerShell Web Access β Just how practical is it?
https://practical365.com/blog/powershell-web-access-just-how-practical-is-it
This is very similar to Azure Cloud Shell.
PowerShell Team: Using PowerShell From a Browser to Manage Cloud Resources by Danny Maertens - YouTube
Because the above is a Web browser console, it can be properly hosted and secured; which means I can use any device with a browser to run PowerShell script, even your phone.
BTW, you can run PS from an HTA (stand-alone local HTML application (only on Windows), just as you could WMI stuff via VBScript in an HTA (stuff like the below was fairly common back in the day)...
<head>
<title>HTA Test</title>
<HTA:APPLICATION
APPLICATIONNAME="HTA Test"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
</head>
<script language="VBScript">
Sub TestSub
Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run("powershell.exe -ExecutionPolicy ByPass-File test.ps1", 0, true)
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("D:\temp\abc.txt", 1)
text = file.ReadAll
alert(text)
file.Close
End Sub
</script>
<body>
<input type="button" value="Run Script" name="run_button" onClick="TestSub"><p>
</body>
... (there is even an IDE for the vbsedit.com); though most orgs/enterprises today block HTA's.
If you want to run PS from a website, that is what N-Tier app deployment is for.
For Example:
DevInfra-US: Using PowerShell 2.0 from ASP.NET Part 1
Create a Powershell Web Application - IT Droplets
Making a powershell script run from aspx - it worked in 1/2 hour! - elbsolutions.com Project List & Blog
Else you'd also look at going down this path:
java - HTML Web page that Launches a PowerShell script - Stack Overflow
then this is a very very bad idea
Even if it is done correctly it is very*30 bad idea.
Also you can bypass all that and just make a .cmd to launch the script - it would work just fine.
An example of a self-contained PS script in the .cmd
Yet, I'm slightly amused by your idea.
And got a little giggle from -RemoteSigned.