每次循环运行时如何创建新变量?
有点像
for ($i=1; $i -le 5; $i++)
{
$"var + $i" = $i
write-host $"var + $i
}
Run Code Online (Sandbox Code Playgroud) 我在一个谷歌文档中有数据.称之为docA.
我想在docB中引用这些数据.有点像=docA!Sheet1!A2
我怎么能这样做?我不介意更改安全设置等
在Machine A
我正在运行端口扫描仪.在Machine B
我想在一个有组织的方式来打开和关闭端口.我希望通过powershell完成所有这些工作.
我发现这个脚本可以运行Machine B
但是当从Machine A
它扫描相同的端口时仍然说它已关闭.
你们中的任何人都知道如何成功打开一个端口 Machine B
编辑::::了解当前的问题状态.
在当前设置中,批处理文件使用以下内容调用powershell脚本
powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4
Run Code Online (Sandbox Code Playgroud)
我想将此转换为一个名为另一个PowerShell的powershell脚本.但是,我在使用启动过程时遇到问题.这是我目前所拥有的,但在执行时,我得到以下内容
No application is associated with the specified file for this operation
Run Code Online (Sandbox Code Playgroud)
这是正在执行的powershell
$powershellDeployment = "D:\path\powershellScript.v32.ps1"
$powershellArguments = "arg1 arg2 arg3 arg4"
Start-Process $powershellDeployment -ArgumentList $powershellArguements -verb runas -Wait
Run Code Online (Sandbox Code Playgroud)
编辑::::::
由于下面的帮助,我现在有以下内容
$username = "DOMAIN\username"
$passwordPlainText = "password"
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password
$powershellArguments = "D:\path\deploy.code.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments
Run Code Online (Sandbox Code Playgroud)
但是,当我从远程计算机执行此脚本时,我收到"访问被拒绝"错误,即使使用的用户名具有对该计算机的完全管理员访问权限
我创建了一个新的rails项目调用
rails new simple_cms
Run Code Online (Sandbox Code Playgroud)
然后在我运行的目录中
rails s
Run Code Online (Sandbox Code Playgroud)
我得到了跟随错误
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/l
ib/mysql2/mysql2.rb:2:in `require': Incorrect MySQL client library version! This
gem was compiled for 6.0.0 but the client library is 5.5.24. (RuntimeError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-
x86-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-
x86-mingw32/lib/mysql2.rb:9:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-
x86-mingw32/lib/mysql2.rb:9:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler/runtime.rb:68:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler/runtime.rb:66:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler/runtime.rb:66:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler/runtime.rb:55:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler/runtime.rb:55:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.1.3/
lib/bundler.rb:119:in `require'
from c:/development/ruby/simple_cms/config/application.rb:7:in `<top …
Run Code Online (Sandbox Code Playgroud) 尝试执行一行代码时出现以下错误
Start-Process : This command cannot be executed due to the error:
Access is denied.
Run Code Online (Sandbox Code Playgroud)
这是正在执行的代码
$username = "domain\username"
$passwordPlainText = "password"
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password
$powershellArguments = "D:\path\ps.script.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments -wait
Run Code Online (Sandbox Code Playgroud)
-wait
但由于用户享有特权,我宁愿保留它我想从网址获取xml提要
http://api.eve-central.com/api/marketstat?typeid=1230®ionlimit=10000002
Run Code Online (Sandbox Code Playgroud)
但似乎失败了.我试过了
http_get
然而,这些都不似乎呼应一个很好的XML饲料时,我要么echo
还是print_r
.最终目标是最终解析这些数据,但将其变为变量肯定是一个不错的开始.
我在下面附上了我的代码.这包含在一个循环$typeID
中,实际上确实给出了正确的ID,如上所示
$url = 'http://api.eve-central.com/api/marketstat?typeid='.$typeID.'®ionlimit=10000002';
echo $url."<br />";
$xml = new SimpleXMLElement($url);
print_r($xml);
Run Code Online (Sandbox Code Playgroud)
我应该说,我看到的另一个奇怪的事情是,当我回复$ url时,我得到了
http://api.eve-central.com/api/marketstat?typeid=1230®ionlimit=10000002
Run Code Online (Sandbox Code Playgroud)
这®
是注册商标符号.我不确定这是我浏览器中的"功能",还是我代码中的"功能"
我有一个变量$users
设置为类似于下面的数组
Array(
[4] => Array(
[userid] => 4
[name] => Mike
[gender] => M
)
[5] => Array(
[userid] => 5
[name] => Sally
[gender] => F
)
[6] => Array(
[userid] => 6
[name] => Steve
[gender] => M
)
)
Run Code Online (Sandbox Code Playgroud)
然后我有代码循环遍历此数组以调用函数来计算年龄.
foreach($users as $user){
$age = getUserAge($user->id);
}
Run Code Online (Sandbox Code Playgroud)
如何获取变量$age
并$users
使用follow数组将其添加到结果中?
Array(
[4] => Array(
[userid] => 4
[name] => Mike
[gender] => M
[age] => 35
)
[5] => Array(
[userid] => 5 …
Run Code Online (Sandbox Code Playgroud) 我有一个类似于此的csv
"fundName","MMFcusip","ticker","AsOfDate","SumHoldingPercent"
"BlackRock OH Muni MMP/Instit","'091927236'","COIXX","2/29/2012 12:00:00 AM","100.00000000200"
"Western Asset Inst US Treas Res","'52470G841'","CIIXX","2/29/2012 12:00:00 AM","100.00000000200"
Run Code Online (Sandbox Code Playgroud)
使用powershell,如何在使用import-csv cmdlet时将"asOfDate"转换为日期/时间?
编辑:这是我目前正在使用的代码行
$measuredDate = $today.AddDays(-21)
$staleDates = Import-Csv d:\path\file.csv | Foreach-Object {$_.AsOfDate = Get-Date $_.AsOfDate} | Where-Object {asOfDate -lt $measuredDate} | Measure-Object
Run Code Online (Sandbox Code Playgroud) 我希望运行该命令
foreach-object {$_ -replace
Run Code Online (Sandbox Code Playgroud)
但是,我试图使用的字符串可以描述如下
this string "has" quotes
Run Code Online (Sandbox Code Playgroud)
整条线都是
foreach-object {$_ -replace "this string "has" quotes", "this string "won't have" quotes"}
Run Code Online (Sandbox Code Playgroud)
如何使这个引用填充行与powershell一起工作?