我想创建一个 powershell 脚本来执行 TCP 端口扫描程序,该扫描程序可以列出给定 IP 地址的开放 TCP 端口。\n这是我到目前为止所做的,这并不完美,我希望得到一些反馈和更正
\n\n port = (80)\n network = (192.168.0)\n ErrorActionPreference= \xe2\x80\x98silentlycontinue\xe2\x80\x99\n { $ip = \xe2\x80\x9c{0}.{1}\xe2\x80\x9d \xe2\x80\x93F $network,$add\n If(Test-Connection \xe2\x80\x93BufferSize 32 \xe2\x80\x93Count 1 \xe2\x80\x93quiet \xe2\x80\x93ComputerName $ip)\n { $socket = new-object System.Net.Sockets.TcpClient($ip, $port)\nRun Code Online (Sandbox Code Playgroud)\n\n问题是它没有扫描所有的 TCP 端口,我不知道如何让它做到这一点。
\n我在 PowerShell 中遇到以下行为,我无法解释并且觉得很麻烦。
我正在任意目录中工作,目录的路径显示在提示中:
PS C:\Users\Rene\AppData\Local\Temp>
Run Code Online (Sandbox Code Playgroud)
另外,get-location报告“正确”路径:
PS C:\Users\Rene\AppData\Local\Temp> get-location
Path
----
C:\Users\Rene\AppData\Local\Temp
Run Code Online (Sandbox Code Playgroud)
然后,我键入命令mkdir xyz | cd以创建一个目录并将工作目录更改为这个新目录:
PS C:\Users\Rene\AppData\Local\Temp> mkdir xyz | cd
Run Code Online (Sandbox Code Playgroud)
突然,提示中的路径带有前缀Microsoft.PowerShell.Core\FileSystem:::
PS Microsoft.PowerShell.Core\FileSystem::C:\Users\Rene\AppData\Local\Temp\xyz>
Run Code Online (Sandbox Code Playgroud)
这一变化也反映在get-location:
PS Microsoft.PowerShell.Core\FileSystem::C:\Users\Rene\AppData\Local\Temp\xyz> get-location
Path
----
Microsoft.PowerShell.Core\FileSystem::C:\Users\Rene\AppData\Local\Temp\xyz
Run Code Online (Sandbox Code Playgroud)
这是怎么回事以及如何关闭该前缀?
我错误地删除了系统变量下的整个 PATH 变量。所以我尝试将一个名为 PATH 的变量显式添加到系统变量中。但现在每当我尝试添加多个路径时,每个路径都会覆盖前一个路径。
正如您所看到的,它没有打开路径列表,而是只提供了一个路径的选项。所以我尝试使用命令行附加 PATH 变量。
setx path "D:\Softwares\MongoDB\bin" /m
它仍然覆盖以前的路径。如图所示,Java 路径(来自屏幕截图 1)被 MongoDB 路径覆盖。
我该如何解决这个问题?如何向 PATH 变量添加多个路径?
PS - 我使用 Windows 10(64 位)。
我可以打开 powershell 并输入
> Ubuntu
Run Code Online (Sandbox Code Playgroud)
在 Windows 10 上打开 WSL ubuntu shell。这将始终将我带到 WSL 主目录。我该如何在 powershell 当前所在的同一位置打开终端?
供参考。我需要这个来为 Windows 资源管理器创建右键单击“在此处打开终端”类型的注册表项。
我正在尝试使用以下方式登录 Azure 门户
Connect-AzAccount
Run Code Online (Sandbox Code Playgroud)
此代码要求我输入我不想要的提示,我们可以使用一些简单的配置脚本自动登录吗?
在 VSCode for PowerShell v5 x64 和 x86 中使用时,Get-ExecutionPolicy -list它返回以下内容:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Bypass
CurrentUser Undefined
LocalMachine Undefined
Run Code Online (Sandbox Code Playgroud)
当在 VSCode 中使用相同的命令并使用 PowerShell v7 控制台时,它会返回:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process RemoteSigned
CurrentUser Undefined
LocalMachine RemoteSigned
Run Code Online (Sandbox Code Playgroud)
有 2 个注册表项设置 ExecutionPolicy(最初:ByPass)
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\0\Command REG_SZ "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process RemoteSigned }; & '%1'"
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\0\Command REG_SZ "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process RemoteSigned }; …Run Code Online (Sandbox Code Playgroud) 我有 velow 脚本
$AddDays = Read-Host "How long user will be active (: in Days) "
$DateInFuture = (Get-date).AddDays($AddDays).ToString('yyyy-mm-dd')
Run Code Online (Sandbox Code Playgroud)
我想在当前日期中添加天数,但我得到了这样的东西..
“2020-57-18”
假设今天是“2020-04-18”,我添加了 5 天...如何使用这种格式添加天数?年-月-日
我想在 powershell 中为cd ..as创建一个别名..。
我尝试遵循变化但无济于事。
Set-Alias ".." "cd .."
Set-Alias ".." { set-location "cd .." }
Set-Alias ".." { set-location ".." }
Run Code Online (Sandbox Code Playgroud) 我们有一个旧的第 3 方系统(我们称之为 Junksoft\xc2\xae 95),我们通过 PowerShell 与之交互(它公开了一个 COM 对象),我正在将其包装在 REST API 中( ASP.NET Framework 4.8 和 WebAPI 2)。我使用System.Management.Automationnuget 包创建一个实例,PowerShell在其中将 Junksoft\ 的 COM API 实例化为一个dynamic对象,然后使用:
//I\'m omitting some exception handling and maintenance code for brevity\npowerShell = System.Management.Automation.PowerShell.Create();\npowerShell.AddScript("Add-Type -Path C:\\Path\\To\\Junksoft\\Scripting.dll");\npowerShell.AddScript("New-Object Com.Junksoft.Scripting.ScriptingObject");\ndynamic junksoftAPI = powerShell.Invoke()[0];\n\n//Now we issue commands to junksoftAPI like this:\njunksoftAPI.Login(user,pass);\nint age = junksoftAPI.GetAgeByCustomerId(custId);\nList<string> names = junksoftAPI.GetNames();\nRun Code Online (Sandbox Code Playgroud)\n\n当我在同一线程上运行所有这些时(例如在控制台应用程序中),这工作得很好。但是,由于某种原因,当我将其放入网络应用程序中的不同控制器并使用它时,这通常不起作用。我说“通常”是因为当 ASP.NET 碰巧向创建的线程发出传入调用时,这实际上会起作用。如果没有,Junksoft 95 会给我一个错误。junksoftAPISystem.Web.Caching.CachejunksoftAPI
我有什么方法可以确保所有交互都junksoftAPI发生在同一个 …
我尝试通过运行在 PowerShell 中设置别名Set-Alias -Name artisan -Value 'php aritsan',尽管命令运行成功,但当我调用别名时,会发生以下错误:
artisan : The term 'php aritsan' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ artisan
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (php aritsan:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)
正确的方法是什么?
PS:artisan是当前目录下的文件。该文件是用laravel框架打包的
powershell ×10
alias ×1
asp.net ×1
azure ×1
c# ×1
cd ×1
filesystems ×1
registry ×1
system-paths ×1
windows-10 ×1