有没有办法将货币字符串转换为浮动值,例如:
$1,138.15
$ 29.10
$2,195.34
Run Code Online (Sandbox Code Playgroud)
应转换为:
1138.15
29.10
2195.34
Run Code Online (Sandbox Code Playgroud)
某些货币字符串在美元符号和美元价值之间有空格.
我这样做是因为我从PDF中提取成本值(转换为txt文件)并对它们进行算术运算.例如,文本文件的一部分如下所示:
Fixed Power
$1,138.15
General Admin Surcharge
$ 29.10
Customer Charge
$2,195.34
Run Code Online (Sandbox Code Playgroud)
我的代码看起来像这样:
$sourceFile = Get-Content $sourcePath\$($filenames[0]).txt
$fixedPower = $sourceFile[(
Select-String `
-Path $sourcePath\$($filenames[0]).txt `
-Pattern "Fixed Power" `
-List
).LineNumber + 1]
$generalAdminSurcharge = $sourceFile[(
Select-String `
-Path $sourcePath\$($filenames[0]).txt `
-Pattern "General Admin Surcharge" `
-List
).LineNumber + 1]
$customerCharge = $sourceFile[(
Select-String `
-Path $sourcePath\$($filenames[0]).txt `
-Pattern "Customer Charge" `
-List
).LineNumber + 1]
Run Code Online (Sandbox Code Playgroud)
但那些只将成本提取到字符串值中.
我试图通过Nagios网络界面禁用对服务的主动检查,但我无法做到.Nagios实例在Centos 5发行版上运行
每次我尝试停止服务时都会收到以下消息:无法打开命令文件'/usr/local/nagios/var/rw/nagios.cmd'进行更新!
虽然我尝试了在网上找到的几个提案:
usermod -a -G nagios apache
chmod 666 /usr/local/nagios/var/rw/nagios.cmd
chown nagios.nagcmd /usr/local/nagios/var/rw
chmod u+rwx /usr/local/nagios/var/rw
chmod g+rwx /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
Run Code Online (Sandbox Code Playgroud)
当然,每次重启nagios服务.
谢谢你的帮助 !干杯
我下面的函数将创建一个HTML表,但是我希望表中的值具有超链接。
Function MyFunction{
clear-host
$item=$null
$hash = $null #hashTable
$hash =@{"Google.com" = "www.google.com"; "Yahoo" = "www.yahoo.com";"My Directory" ="C:\Users\Public\Favorites" ;"MSN" = "www.msn.com"}
ForEach($item in @($hash.KEYS.GetEnumerator())){
$hash | Sort-Object -Property name
}
$hash.GetEnumerator() | sort -Property Name |Select-Object Name, Value | ConvertTo-HTML | Out-File .\Test.html
}
MyFunction
Run Code Online (Sandbox Code Playgroud) 我正在尝试进入 Powershell 并尝试将一个简单的 JSON 文件转换为表格格式。
json 文件如下所示:
{ "Members" : [
{ "Id" : 1,
"Details" : [ { "FirstName" : "Adam" }, { "LastName" : "Ant" } ] },
{ "Id" : 2,
"Details" : [ { "FirstName" : "Ben" }, { "LastName" : "Boggs" } ] },
{ "Id" : 3,
"Details" : [ { "FirstName" : "Carl"} , { "LastName" : "Cox" } ] }
]
}
Run Code Online (Sandbox Code Playgroud)
Powershell 表达式:
$jString.Members.details | Select-Object -Property Id, FirstName, LastName
Run Code Online (Sandbox Code Playgroud)
到目前为止的输出(我得到的最好).. …
我正在测试一些域名以及他们在发生异常事件时提醒我的能力.我正在使用nmap扫描域的开放端口.下面的脚本打开一个新的cmd窗口并运行nmap.我搜索进程ID并检查进程(cmd)是否仍在运行.扫描结束后,它将再次运行nmap扫描.
function nmaptest {
$prog1="cmd"
$params1=@("/C";"nmap.exe -Pn -sX 192.168.1.0/24")
Start-Process -Verb runas $prog1 $params1 #starts
}
while(1 -eq 1){
nmaptest
$processes = get-process $prog1 | out-string
$sp = $processes.Split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)
$procid = $sp[22]
echo $procid
while(get-process -id $procid){ }
}
Run Code Online (Sandbox Code Playgroud)
这很好用.我需要帮助的是并行执行此过程8次.(如果可能的话)
我想在类似于此的PowerShell查询中获取组名,按名称管理和通过电子邮件管理.
Get-ADGroup -filter {Name -like "*Admins" }
Run Code Online (Sandbox Code Playgroud)
输出看起来类似于:
Group Name | Managed By Name | Managed By Email
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是加入Get-ADGroup和Get-ADUser.在SQL中,这种"连接"会发生get-adgroup.managedby = get-aduser.distinguishedname.我知道这不是它在Powershell中的工作原理,只是想我会抛出一个我想要做的事情的例子.
任何帮助都会受到欢迎和赞赏.
我试图从 中的数组中提取项目$IOC,然后对于每个项目替换 $API here-string 中的 $IMPORT 并将结果回显到控制台,然后对数组中的每个项目执行此操作$IOC。
#put IOC\'s into array\n$IOC= \xe2\x80\x98c:\\Users\\powershell_array.txt\'\n#api curl script with variable to be replaced\n$API = @"\ncurl --insecure \'https://192.168.1.1:3000/hx/api/v2/indicators/Custom/Powershell_AD/conditions/execution\' -X \'POST\' --data-binary "\n{ \n \\"tests\\":[ \n { \n \\"token\\":\\"processEvent/ActiveDirectory\\",\n \\"type\\":\\"text\\",\n \\"operator\\":\\"contains\\",\n \\"preservecase\\":false,\n \\"value\\":\\"$IMPORT\\"\n }\n ]\n}" -H \'X-FeApi-Token: IAOaiq1s2\' -H \'Accept: application/json\' -H \'Content-Type: application/json\'"\n"@\n\nForEach ($i in Get-Content $IOC) {$API -replace $IMPORT, $i} echo $API\nRun Code Online (Sandbox Code Playgroud)\n\n我没有收到错误,但它只是打印数组的内容,然后当然会回显$API一次而不进行替换。
为什么System.Net.IpAddress允许以下字符串转换为有效的 IP 地址?
$b = [ipaddress]"10.10.10"
$b.IPAddressToString
#10.10.0.10
$c = [ipaddress]"10.10"
$c.IPAddressToString
#10.0.0.10
$d = [ipaddress]"10"
$d.IPAddressToString
#0.0.0.10
Run Code Online (Sandbox Code Playgroud)
我可以看到模式是字符串中的最后一个八位字节是IPAddress对象中的最后一个八位字节,无论字符串中的第一个八位字节是什么,都用作 中最左边的八位字节IPAddress,并使用零填充中间未指定的八位字节,如果有的话。
但它为什么要这样做呢?作为用户,除非指定了所有八位字节,否则我希望它在转换过程中失败。因为它允许这些转换,所以在检查字符串是否是有效的 IP 地址时可能会出现这样的意外结果:
[bool]("10" -as [ipaddress]) #Outputs True
Run Code Online (Sandbox Code Playgroud) 有没有办法-Filter使用 WMI 查询语言 (WQL) 指定 Get-WmiObject cmdlet的参数,以根据用于调用进程的“命令行”进行过滤?“命令行”是指 Windows 任务管理器的“进程”选项卡中显示的“命令行”。
我想获取一个进程 id 数组,其中命令行包含 string *Dev_SW*。我不能使用名称,因为会有许多不等于*Dev_SW*过滤器的同名进程在运行。
我试图了解Windows计算机是否需要重新启动。但是,我的脚本抛出了错误。
powershell "$key = Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue"
Error :
Get-Item : A positional parameter cannot be found that accepts argument
'Update\RebootRequired'.
At line:1 char:8
+ $key = Get-Item
HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Aut ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindin
gException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.GetItemCommand
Run Code Online (Sandbox Code Playgroud)
我在“命令提示符”中运行此命令。不知道是什么意思!