目前,我正在通过PowerShell的自动化计划任务的创造,我使用的New-ScheduledTaskAction,New-ScheduledTaskTrigger和Register-ScheduledTask命令。现在,我有一些作业需要在以下条件下运行:
虽然TechNet文档的New-ScheduledTaskTrigger命令指定Daily和Weekly时间跨度参数,我没有看到一个Monthly,这是定义上述的运行时间是至关重要的。
在我使用 Powershell 的几年中,我想不出一个实例可以通过标准 UI 界面执行某些操作,而使用可用命令之一无法完成这些操作。
这只是在这里不可用,还是我错过了什么?
更新 #1
我只是偶然发现了这个SuperUser question,它看起来很有希望,但引用了 PSV3 而不是 PSV4 - 打算试一试并报告。
我有一个从事件处理程序调用 powershell 脚本的程序。powershell脚本是第三方提供的,我没有任何控制权。
powershell 脚本使用 powershell 进度条。我需要阅读 powershell 脚本的进度,但是由于进度条 System.Management.Automation 命名空间不会将其视为输出。是否可以从外部程序读取 powershell 进度条的值?
进程进程=新进程();
Run Code Online (Sandbox Code Playgroud)process.StartInfo.FileName = "powershell.exe"; process.StartInfo.Arguments = String.Format("-noexit -file \"{0}\"", scriptFilePath); process.Start();
我得到以下命令:
Get-Mailbox | Get-MailboxPermission | Select-Object Identity,User,AccessRights | Format-Table -AutoSize. 我希望能够PrimarySMTPAddress从我获得Get-Mailbox. 在我添加属性的那一刻,我PrimarySMTPAddress在列中什么也没有收到。
最终结果应该是这样的:
Identity User AccessRights PrimarySMTPAddress
-------- ------ ------------ ------------------
Domain.local/Users/Mailbox1 User1 {FullAccess} Mailbox1@Domain.local
Domain.local/Users/Mailbox2 User2 {FullAccess} Mailbox2@Domain.local
Domain.local/Users/Mailbox3 User3 {FullAccess} Mailbox3@Domain.local
Run Code Online (Sandbox Code Playgroud) 我有以下脚本来启动应用程序:
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
$args = "arguments"
$proc = Start-Process -PassThru "path" -ArgumentList $args
start-sleep -Seconds 5
[Microsoft.VisualBasic.Interaction]::AppActivate($proc.Id)
[System.Windows.Forms.SendKeys]::SendWait("~")
Run Code Online (Sandbox Code Playgroud)
我使用这个脚本来启动几个需要用户交互才能启动的 Windows 窗体应用程序(即按下启动按钮)。到目前为止,我一直在让脚本休眠 5 秒钟以允许应用程序启动。我尝试在具有不同处理能力的各种计算机上运行此脚本,但并没有在所有计算机上运行,有些计算机启动应用程序比其他计算机慢,当应用程序启动应用程序超过 5 秒时脚本失败,因为AppActivate 找不到 PID。我不想为每台计算机尝试不同的睡眠时间,因为我必须在启动时在 100 多台计算机上运行此脚本。
我想知道是否有办法以事件驱动的方式等待应用程序启动。
更新:
WaitForInputIdle 不适用于我尝试启动的所有应用程序。它立即返回(成功是因为它返回 true)并且 AppActive 方法抛出异常。
我正在尝试使用 Powershell 递归读取一些注册表设置。这是我尝试过的:
$registry = Get-ChildItem "HKLM:\Software\Wow6432Node\EODDashBoard\moveFilesOverflow" -Recurse
Foreach($a in $registry) {
Write-Output $a.PSChildName
$subkeys = (Get-ItemProperty $a.pspath)
Write-Output $subkeys.LastDateTime_EndScript
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在不知道注册表项的情况下列出所有注册表项及其值。
在我的脚本中,我有一个变量 $subkeys,其中包含我可以访问的对象。(例如在这里我可以访问$subkeys.LastDateTime_EndScript)
但是,我想要的是在不知道脚本中的注册表项的情况下列出所有注册表项及其值,即如下所示:
Foreach ($subkey in $subkeys) {
Write-Output $subkey.keyname
Write-Output $subkey.value
}
Run Code Online (Sandbox Code Playgroud)
是否可以?谢谢,
我需要在字符串中搜索反斜杠的数量来确定一些文件路径参数。我还没有找到一种方法来搜索反斜杠,而 Powershell 认为它是一个转义字符。
([regex]::Matches($FilePath, "\" )).count
Run Code Online (Sandbox Code Playgroud)
或者
$a -match "\"
Run Code Online (Sandbox Code Playgroud)
这些都出现错误“模式末尾非法\”
谢谢!
升级到 Windows Management Framework 5.0 后,我在获取 DSC 配置时开始收到以下异常。
ConvertTo-MOFInstance : System.ArgumentException error processing property 'Password' OF TYPE 'MSFT_Credential': Certificate
'---HIDDEN-CERTIFICATE-THUMPRINT-VALUE---' cannot be used for encryption. Encryption certificates must contain the Data Encipherment or Key
Encipherment key usage, and include the Document Encryption Enhanced Key Usage (1.3.6.1.4.1.311.80.1).
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:303 char:13
+ ConvertTo-MOFInstance MSFT_Credential $newValue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], InvalidOperationException
Run Code Online (Sandbox Code Playgroud)
每个节点上使用的证书是使用以下证书请求生成的自签名证书。
[NewRequest]
Subject = CN=[computer-name-here].dsc
KeyLength = 2048
MachineKeySet = true
RequestType = Cert
KeySpec = AT_KEYEXCHANGE
Run Code Online (Sandbox Code Playgroud)
然后将此请求文件馈送到 …
我正在寻找Powershellcmd 来打印目录中任何文件的最后 5 行数据。
理想情况下
Get-Content -Tail 5 -Wait .\test.log
将在最后 5 行的特定文件上打印尾部。如果有任何新内容被附加到该文件,它将继续打印。
同样,我想跟踪目录中的所有文件。如果任何文件被修改,则打印内容。
试过这样的东西,没有用!
Get-Content -Tail 5 -Wait .\folder*.log
当我尝试使用 Powershell cmdlet Stop-AzureRMVM(新 ARM 的)停止 Azure 上的虚拟机时,我收到如下所示的消息框。有这个问题,如果我在批处理语句中运行它,我会在 VM 关闭的每个语句中收到此消息框/提示。我如何抑制这个?
是否有单一的保证方法来测试当前用户是否具有管理员权限?我试过这个
$isAdmin = (new-object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole("Administrators")
Run Code Online (Sandbox Code Playgroud)
只要 Windows 最初是用英文安装的,它就可以工作。如果 Windows 以西班牙语安装,您必须测试 Administra d ors。还有一些其他语言的工作方式类似。我的第一个想法是测试所有可能的拼写,但如果有一些简单、优雅和万无一失的东西,那将是我的首选。
powershell ×10
azure ×1
backslash ×1
c# ×1
certificate ×1
dsc ×1
pipeline ×1
recursion ×1
registry ×1
tail ×1