简体   繁体   English

Azure Powershell ISE执行查询

[英]Azure Powershell ISE Execution query

I am using azure powershell ISE. 我正在使用Azure Powershell ISE。 I have a very long script to run where I am using variables to store data and further I am using them in my code. 我有一个很长的脚本,可以在其中使用变量存储数据并在代码中使用它们的地方运行。 The problem is I am not able to run this script in a single go, reason being execution is not line by line. 问题是我无法一次运行此脚本,原因是执行不是逐行执行。 Sometimes it tries to execute a command before the variable is assigned its value. 有时,它会在分配变量值之前尝试执行命令。 It throws an error. 引发错误。

I want to run 200 lines of code having 30 variables in a single go using powershell ISE. 我想使用Powershell ISE一次运行200行代码,其中包含30个变量。 Eg. 例如。 Problem is- 问题是-

Get-azurevm -servicename $a -vmname $b

is getting executed before $a= xxx $b= yyy is getting initialized.I have initialized my variables before using but I guess execution fashion is not line by line. 在$ a = xxx $ b = yyy被初始化之前被执行。我在使用之前初始化了变量,但我猜执行方式不是逐行的。

What could be the possible solution for this? 有什么可能的解决方案?

Is there any option I can make the execution line by line ? 我可以逐行执行任何选项吗?

Azure PS execution is always line by line. Azure PS执行总是逐行执行。 If something like this is happening you can break the code into function and you can execute your desired code to execute only if the before ones codes have already been executed. 如果发生这种情况,则可以将代码分解为功能,并且只有在之前的代码已经执行过的情况下,才可以执行所需的代码。 It is always good to go with modules if u have a long code. 如果您有很长的代码,最好使用模块。

Also you can use- 您也可以使用-

start-sleep -s "no. of seconds to give other code to execute"

for execution of code which takes a bit longer time. 花费更长的时间来执行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM