GVKun编程网logo

Windows Powershell For 循环(powershell循环语句)

3

此处将为大家介绍关于WindowsPowershellFor循环的详细内容,并且为您解答有关powershell循环语句的相关问题,此外,我们还将为您介绍关于AWSisupdatingminimumr

此处将为大家介绍关于Windows Powershell For 循环的详细内容,并且为您解答有关powershell循环语句的相关问题,此外,我们还将为您介绍关于AWS is updating minimum requirements for AWS Tools for PowerShell to Windows PowerShell 3.0 and ....、AzureDevOps Powershell 任务命令行参数未在 Powershell 脚本中正确呈现、Kubernetes powershell 模块的 Powershell cmdlet 参考、Linux/Wine:windows 应用程序启动 windows 控制台命令并在 windows 上等待时在 linux 上不等待:如何修复?的有用信息。

本文目录一览:

Windows Powershell For 循环(powershell循环语句)

Windows Powershell For 循环(powershell循环语句)

如果你知道循环的确切次数可以使用For循环,For循环属于计数型循环,一旦达到最大次数,循环就会自动终止。下面的例子通过循环求1-100的数列和。

复制代码 代码如下:

$sum=0
for($i=1;$i -le 100;$i++)
{
    $sum+=$i
}
$sum

For循环是特殊类型的While循环

在For循环开始的圆括号中,由分号隔开的语句为循环的控制条件,分别为:初始化,循环执行满足的条件,增量。
For循环的控制语句第一个和第三个可以为空:

复制代码 代码如下:

$sum=0
$i=1
for(;$i -le 100;)
{
    $sum+=$i
    $i++
}
$sum

For循环的特殊应用

上面的For循环示例停留在数字层面上,其实While循环能办到的事,For循环也可以,只是可能有时不方便而已。例如判断域名的例子:

复制代码 代码如下:

for($domain="";!($domain -like "www.*.*");$domain=Read-Host "Input domain")
{
    Write-Host -ForegroundColor "Green" "Please give a valid domain name."
}
Please give a valid domain name.
Input domain: www
Please give a valid domain name.
Input domain: mossfly.com
Please give a valid domain name.

下面的例子演示逐行读取文本文件

复制代码 代码如下:

for($file=[IO.File]::OpenText("c:autoexec.bat") ; !($file.EndOfStream);$line=$file.ReadLine() )
{
    $line;
}
$file.Close()
REM Dummy file for NTVDM

您可能感兴趣的文章:

AWS is updating minimum requirements for AWS Tools for PowerShell to Windows PowerShell 3.0 and ....

AWS is updating minimum requirements for AWS Tools for PowerShell to Windows PowerShell 3.0 and ....

https://amazonaws-china.com/blogs/developer/aws-is-updating-minimum-requirements-for-aws-tools-for-powershell-to-windows-powershell-3-0-and-net-framework-4-5/


On January 14th 2020 Microsoft ended extended support for Windows Server 2008 and Windows Server 2008 R2. The oldest supported Windows Server version, Windows Server 2012, comes with Windows PowerShell 3.0 and .NET Framework 4.5.

The legacy variant of AWS Tools for PowerShell (AWSPowerShell) is currently compatible with Windows PowerShell 2.0 and .NET Framework 3.5. Starting May 1st 2020, AWS will require Windows PowerShell 3.0+ and .NET Framework 4.5+ as prerequisite for all new releases of AWSPowerShell. The existing versions of AWSPowerShell that are compatible with Windows PowerShell 2 and .NET Framework 3.5 will continue to be available for download from PowerShell Gallery, but will not be updated or supported.

What do I need to do?

AzureDevOps Powershell 任务命令行参数未在 Powershell 脚本中正确呈现

AzureDevOps Powershell 任务命令行参数未在 Powershell 脚本中正确呈现

如何解决AzureDevOps Powershell 任务命令行参数未在 Powershell 脚本中正确呈现

我有一个 AzureDevops Powershell 任务,它将从 keyvault 读取的值作为参数传递给脚本。即使在 DevOps 任务中使用双引号或单引号将变量括起来,脚本中的值也不会显示正确。

我还需要做什么才能将这些值正确传递给脚本?

有一个 older similar question,答案是双引号任务中的参数,我已经这样做了,但无济于事。

示例 Powershell 任务:

  1. ScriptArguments: -connectionString "$(ConnString)" -password "$(ConnStringPassword)"

存储在 keyvault 中的示例值:

  1. ConnString: Server=tcp:test-sqldb.database.windows.net,1433;Initial Catalog=TestDb;Persist Security Info=False;
  2. ConnStringPassword: Pa$$w0rd

示例脚本:

  1. param (
  2. [string]$connectionString,[string]$password
  3. )
  4. Write-Host "connectionString: $connectionString"
  5. Write-Host "password: $password"

管道执行的示例输出:

  1. connectionString: ***
  2. password: Paw0rd

如果我按照下面@Thomas 的建议在管道任务中使用单引号:

示例 Powershell 任务:

  1. ScriptArguments: -connectionString ''$(ConnString)'' -password ''$(ConnStringPassword)''

流水线执行的示例输出:

  1. connectionString: ***
  2. password: ***

解决方法

@ShaykiAbramczyk 是正确的,秘密是不可见的。然而,这些值在 Powershell 脚本中得到了正确利用。我通过发布测试输出文件并查看 KeyVault 值在输出文件中来验证这一点。以下参考资料让我想到了发布以查看值,而不是尝试回显或将它们写入控制台。

Use secrets from Azure Key Vault in Azure Pipelines

Kubernetes powershell 模块的 Powershell cmdlet 参考

Kubernetes powershell 模块的 Powershell cmdlet 参考

如何解决Kubernetes powershell 模块的 Powershell cmdlet 参考?

在哪里可以看到 k8s 模块 here 的 cmdlet 参考?

谢谢

解决方法

这是为了更好的可见性而发布的社区 wiki 答案。

正如评论中已经提到的,您正在寻找的参考资料可以在 here(module page 左侧的 Project Site 链接)中找到。

Linux/Wine:windows 应用程序启动 windows 控制台命令并在 windows 上等待时在 linux 上不等待:如何修复?

Linux/Wine:windows 应用程序启动 windows 控制台命令并在 windows 上等待时在 linux 上不等待:如何修复?

如何解决Linux/Wine:windows 应用程序启动 windows 控制台命令并在 windows 上等待时在 linux 上不等待:如何修复??

除了一项功能外,我还使用 Wine 成功运行了 Windows 程序。该程序可以设置为在 texlive 发行版中启动 pdflatex,当它启动时,它等待查看结果是否成功,然后复制/移动文件。但是在 Linux 上,我无法安排它像在 Windows 上那样等待 pdflatex 完成,因此过早地复制/移动文件并且 pdflatex 无法找到它们。

有一个对话框可以用来保存任意命令,当我按下应用程序中的 pdflatex 按钮时,该命令将被执行。我将此对话框指向 Windows 上的 C:\texlive\2020\bin\win32\pdflatex.exe 并且它可以工作。除了不等待的问题外,我成功地放置了这个命令,以便在Linux上使用wine运行pdflatex。

Z:/usr/bin/gnome-terminal --wait -- /home/nonnull/bin/runlatex/runlatex.sh "%f"

通过将 runlatex.sh 中的最后一个命令设为 exec /bin/bash,终端保持打开状态,因此我可以看到 pdflatex 的所有输出,并知道它正在使用 runlatex.sh 必须找出的正确文件运行通过将传递给它的 Windows 路径转换为其实际路径。 pdflatex 以各种方式抱怨它在那里创建的文件,然后在运行期间不存在。即使终端是打开的,所以没有完成执行,应用程序抱怨 pdflatex 没有正确完成,甚至在 pdflatex 的输出文本完成向下滚动终端之前。当我省略 exec 时,应用程序的行为不会改变终端立即关闭时的命令 pdflatex 完成。

Wine 是怎么回事,命令在完成运行之前不会保持附加状态?我该怎么办?对可以绕过这个困难的命令或机制有什么建议吗?如果需要的话,我准备编写一个 win32 程序来进行调解。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

关于Windows Powershell For 循环powershell循环语句的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于AWS is updating minimum requirements for AWS Tools for PowerShell to Windows PowerShell 3.0 and ....、AzureDevOps Powershell 任务命令行参数未在 Powershell 脚本中正确呈现、Kubernetes powershell 模块的 Powershell cmdlet 参考、Linux/Wine:windows 应用程序启动 windows 控制台命令并在 windows 上等待时在 linux 上不等待:如何修复?的相关知识,请在本站寻找。

本文标签: