是否可以使用选项调用PowerShell脚本?就像没有值的参数一样.
例如,我目前使用:
param (
$lastmonth=0
);
Run Code Online (Sandbox Code Playgroud)
在脚本中.现在我可以使用这个电话了
script.ps1 -lastmonth 1
Run Code Online (Sandbox Code Playgroud)
要么
script.ps1
Run Code Online (Sandbox Code Playgroud)
并使用$ lastmonth来控制流量.
但我想接听电话
script.ps1 -lastmonth
Run Code Online (Sandbox Code Playgroud)
和
script.ps1
Run Code Online (Sandbox Code Playgroud)
并根据是否给出-lastmonth来控制流量.
情况.在Windows 7 SP1计算机上,我已使用Windows6.1-KB2819745-x64-MultiPkg.msu进行了更新.此外,在PowerShell $ PSVersionTable现在报告'PSVersion 4.0'.
目前,我的结论是许多PowerShell 4 cmdlet如Test-NetConnection,只能在Windows 8.1上运行.但是,我想知道是否有可以在我的Windows 7机器上导入PowerShell 4模块的解决方法.
我一直在努力寻找答案,但我认为在一组关键字中将PowerShell和参数放在一起并不能轻松搜索
我的问题是,我正在编写一个函数,并且我提供了一个参数,但参数必须是特定字符串列表中的一个.
有没有办法在脚本中提供这些字符串,这样如果我输入"myfunction -parameter ..",我可以使用tab完成参数值吗?
我想替换多个文件和文件夹中的文本.文件夹名称更改,但文件名始终为config.xml.
$fileName = Get-ChildItem "C:\config\app*\config.xml" -Recurse
(Get-Content $fileName) -replace 'this', 'that' | Set-Content $fileName
Run Code Online (Sandbox Code Playgroud)
当我运行上面的脚本时,它可以工作,但它在config.xml中写入整个文本大约20次.怎么了?
我很好奇为什么Start-Job增加了两个.我担心的是我做错了什么使得新工作的ID跳了2.
Start-Job -ScriptBlock {Get-WinEvent -LogName system -MaxEvents 1000}
Run Code Online (Sandbox Code Playgroud)
结果如Get-Job所示
Id Name State HasMoreData Command
-- ---- ----- ----------- -------
2 Job2 Completed False Get-WinEvent -LogName system -MaxEvents 1000
4 Job4 Completed False Get-WinEvent -LogName system -MaxEvents 1000
6 Job6 Completed True Get-WinEvent -LogName system -MaxEvents 1000
Run Code Online (Sandbox Code Playgroud)
问题:您可以控制Start-Job Id增量,还是强制它们只是1?
我在网页上有一个输入类型=文本输入框我加载并填充值并单击提交按钮,工作正常:
$ie=New-Object -comobject InternetExplorer.Application
$ie.visible=$true
$ie.Navigate("https://myurl/test.html")
while($ie.busy){Start-Sleep 1}
$ie.Document.getElementById("field_firstName").value="Firstname"
$ie.Document.getElementById("field_lastName").value="Lastname"
$ie.Document.getElementById("btn_upload").Click()
while($ie.busy){Start-Sleep 1}
Run Code Online (Sandbox Code Playgroud)
我还想用c:\ temp\test.txt 填充输入类型=文件框并上传它.我读到,由于安全原因,浏览器不支持value =.
使用PowerShell有没有解决方法?也许"点击"浏览按钮并选择文件或使用sendkeys?
我的任务是按键盘序列,如Ctrl+ Shift+ R,重新启动Windows服务。
我有一个在 PowerShell ISE 中运行良好的脚本,当以管理权限启动时。
当我尝试使用 PowerShell 脚本时,由于管理权限不足而失败。我可以让它与老式的 bat 文件一起工作,但不能与 PowerShell 一起工作,这真是令人恼火。
问题的根源在于 PowerShell 脚本的快捷方式的管理权限框变灰。到目前为止,还没有解决方法可以克服这个特权问题。
有任何想法吗?
情况:
Get-ChildItem $Path -Filter *.dll 为我工作
这有效:
$Path = "$env:windir\system32\*"
$GuyArray = @("*.dll", "*.exe")
Get-ChildItem $Path -Include $GuyArray
Run Code Online (Sandbox Code Playgroud)但是我无法使它工作:
$Path = "$env:windir\system32\*"
$GuyArray = @("*.dll", "*.exe")
Get-ChildItem $Path -Filter $GuyArray
Run Code Online (Sandbox Code Playgroud)错误信息:
无法将“ System.Object []”转换为参数“ Filter”所需的类型“ System.String”。不支持指定的方法。
问题:
-Include支持多个值,但-Filter仅允许一个值?Get-Help gci呢?我想模仿PowerShell 3.0
在PowerShell v3或v4中,您可以使用以下命令模拟v2:
%windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe -version 2
Run Code Online (Sandbox Code Playgroud)
$ Host揭示:版本:2.0
但是,在PowerShell 4中
%windir%\system32\WindowsPowerShell\v1.0\PowerShell.exe -version 3
Run Code Online (Sandbox Code Playgroud)
$ Host now报告:版本:4.0(我希望3:0)
问题:有没有办法从4.0模拟PowerShell 3.0?
PowerShell(和其他程序)提供"以管理员身份运行"的功能.是否有注册表我们可以更改设置以使其成为默认设置?因此,无需右键单击并以"以管理员身份运行"?
我的任务是从使用PowerShell开始创建一个Outlook实例,只需查看或显示我在TaskManager中可以看到的进程.
对于Digress,这适用于Word.Application
但不适用于Outlook.Application.
$MsApp = New-Object -comObject Word.Application
$MsApp.Visible = $true
Run Code Online (Sandbox Code Playgroud)
我已经检查了方法,但找不到合适的动词来打开,运行或显示.
我会非常感谢解决方案.
我有一个看起来像这样的powershell脚本p1.ps1(不完全是,但这可以作为一个例子):
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Do the action."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Exit."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
Run Code Online (Sandbox Code Playgroud)
如何编写另一个脚本p2.ps1,它将运行第一个脚本(p1.ps1)并为其提供答案,以便p2.ps1执行时不会问任何问题?
我试过了:
echo y | p1.ps1
Run Code Online (Sandbox Code Playgroud)
但它没有做到这一点.
powershell ×12
directory ×1
file ×1
file-upload ×1
filter ×1
html ×1
input ×1
outlook ×1
parameters ×1
registry ×1
replace ×1
scripting ×1
shortcut ×1
windows-7 ×1