我试图获取文本doc中每行的字符数.我的文档文档的内容是:
1
15
69
124
300
Run Code Online (Sandbox Code Playgroud)
我一直在尝试PS脚本的变种:
get-content c:\serverlist.txt | foreach-object {measure-object -character}
Run Code Online (Sandbox Code Playgroud)
但我能得到的最好的回报是:
行词字符属性
------- -------- -------------- -----------
0
0
0
0
0
不知道我在这里缺少什么,但任何帮助将不胜感激!
谢谢!
有什么区别:
$A="Something"
Run Code Online (Sandbox Code Playgroud)
和
$A.Value="Something"
Run Code Online (Sandbox Code Playgroud)
我看到这只在.Value使用时才有效:
function main
{
$A="Original A"
$B="Original B"
SetByRef1 ([ref]$A)
SetByRef2 ([ref]$B)
$A
$B
#output: Changed A
#output: Original B
}
function SetByRef1([ref]$A)
{
$A.Value = "Changed A"
}
function SetByRef2([ref]$B)
{
$B = "Changed B"
}
main
Run Code Online (Sandbox Code Playgroud)
我想,这$B = "Changed B"是定义一个新变量B,而$A.Value = "Changed A"只是改变内容,但我还没有找到确认.
(我确定这是重复的,但我还没找到)
我是 Powershell 的新手,但这让我有点疯狂。我在这里查看了各种问题,但找不到答案,所以我就在这里。如果已经涵盖了这一点,我们深表歉意。
我有两个包含数字列的文本文件。我想创建一个包含这两列的数组,并按第 1 列或第 2 列对其进行排序。
如果我们有
$a=@(1,5,10,15,25)
$b=@(100,99,98,99,10)
Run Code Online (Sandbox Code Playgroud)
我们创造
c$=$a,$b
Run Code Online (Sandbox Code Playgroud)
我最初的想法是尝试这样的事情:
$c | sort { [int]$_[0] }
Run Code Online (Sandbox Code Playgroud)
但这不起作用。我尝试过很多不同的事情,所以任何建议将不胜感激。
我正在编辑这个,因为我的问题不太清楚。最终,如果我按升序第 2 列对 $c 进行排序,我期望类似:
25,10
10,98
5,99
15,99
1,100
Run Code Online (Sandbox Code Playgroud)
知道如何实现这一目标吗?
我不知道为什么我发现这么难.从特定的注册表项下,我想根据数据(而不是名称)查询某些注册表值,并删除生成的注册表值.
例如:

如何删除此键中包含的任何值,例如"foo".我可以列出注册表值Get-ItemProperty 'HKCU:\Software\Policies\Google\Chrome\RestoreOnStartupURLs',但它将一些垃圾与实际数据混合在一起:
1 : http://foo.example.com
2 : http://bar.example.com
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Policies\Google\Chrome\RestoreOnStartupURLs
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Policies\Google\Chrome
PSChildName : RestoreOnStartupURLs
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Run Code Online (Sandbox Code Playgroud)
我试图管道Where-Object但无法找到有效的查询.然后我需要一个Remove-可以处理结果的cmdlet.有人有主意吗?
我在 PowerShell 中有一些代码,我需要在 cmd.exe 中使用它
我在 cmd.exe 中使用这个命令
powershell -command "command"
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误
powershell -command "command"
Run Code Online (Sandbox Code Playgroud)
我的命令是:
powershell -command "(Get-Content D:\15.txt -TotalCount 3)[-1] | Foreach-object {$_ -replace "REG_SZ", " "} | Foreach-object {$_ -replace "Gmail", " "} | set-content D:\15.txt"
Run Code Online (Sandbox Code Playgroud) 有没有办法使用Read-Hostcmdlet 捕获多行?
我目前的方法有点尴尬(并且实际上不起作用):
PS> Send-MailMessage -SmtpServer 'smtp.domain.xxx' -From 'First Last <flast@domain.xxx>' -To 'First Last <first.last@company.com>' -Subject 'Testing' -Body (Read-Host 'Enter text')
Enter text: line one `n line two `n line three
Run Code Online (Sandbox Code Playgroud)
生成的电子邮件正文不是三行:
line one `n line two `n line three
我在PowerShell中使用Task Scheduler cmdlet为Perfmon Data Collector集的计划任务配置触发器.我正在使用以下内容修改计划任务并在服务器启动时启动数据收集器集:
$trigger = New-ScheduledTaskTrigger -AtStartup
Set-ScheduledTask -TaskPath '\Microsoft\Windows\PLA\' -Taskname $TemplateName -Trigger $trigger
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有一种方法可以从计划任务配置中删除此触发器.我不想禁用计划任务,只想从计划任务中删除此触发器.
看起来有一种方法可以从PowerShell cmdlet中执行此操作.任何帮助将不胜感激.
输出示例:
#TYPE System.Data.DataRow <---
"PersonalNr" <---
"00001005"
"00001008"
"00001009"
"00001013"
"00001019"
"00001024"
Run Code Online (Sandbox Code Playgroud)
要求:
我想要一个没有前 2 行和引号的输出,我该怎么做?
对于标题,我尝试了选项,-h -1但输出仍然相同。甚至有可能Sqlcmd吗?
当前代码:
Invoke-Sqlcmd -ServerInstance SERVER -h -1 -Query $QueryFmt | Export-CSV $AttachmentPath
Run Code Online (Sandbox Code Playgroud) 我不知道如何使用列表从系统中记录多个指标。该$CounterList变种不工作,但该$CounterList_Working变种一样。我见过根据路径获取列表的示例,例如(Get-Counter -List Processor(*)).Paths.
我以为我可以在变量中指定路径,但这不起作用。
什么是错的$CounterList在PowerShell脚本?我收到的错误消息是“Get-Counter:在计算机上找不到指定的对象。”。这让我认为它试图将列表作为单个值读取。
$CounterList = "\Network Interface(*)\Packets/sec
\Network Interface(*)\Current Bandwidth
\Network Interface(*)\Bytes Total/sec
\Memory\Committed Bytes
\Memory\Commit Limit"
$CounterList_Working = "\Processor(*)\% Processor Time"
echo "Gathering system data and writing to file $home\system_metrics.blg"
Get-Counter -Counter $CounterList -SampleInterval 2 -MaxSamples 10 | Export-counter -Path $home\system_metrics.blg
Run Code Online (Sandbox Code Playgroud) 我有一个 PowerShell 脚本,可以在 Internet Explorer 中打开某个链接。到目前为止我有以下代码。它会打开链接,但当我特别需要在 Internet Explorer 中打开它时,它会发送到我的默认浏览器。
$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\TMW.lnk")
$ShortCut.TargetPath="http://tmw1.casttrans.com/rdweb"
$ShortCut.WorkingDirectory = "C:\Program Files (x86)\Internet Explorer";
$ShortCut.WindowStyle = 1;
$ShortCut.IconLocation = "iexplore.exe, 0";
$ShortCut.Save()
Run Code Online (Sandbox Code Playgroud) powershell ×10
cmd ×1
expression ×1
performance ×1
registry ×1
shortcut ×1
sorting ×1
variables ×1
windows ×1