该脚本首先声明一个参数:
param([Parameter(Position=0, Mandatory = $true)]$a)
Run Code Online (Sandbox Code Playgroud)
当我运行脚本而不传递任何参数时,我得到:
Cmdlet test.ps1 at command pipeline position 2
Supply values for the following parameters:
a:
Run Code Online (Sandbox Code Playgroud)
我想隐藏第一行“Cmdlet test.ps1...”,这对用户来说听起来很尴尬。然后我想指定 $a 参数的文本请求,而不是仅显示其变量名称。
我正在尝试通过DSC配置目标节点.
我创建了一个带有虚拟配置的.ps1文件; 你可以在下面看到它; 它只是您在DSC站点中找到的第一个示例之一.
现在我想将它编译成.mof文件.我执行了:
PS C:\var\DSC\Configurations> . .\localhost.ps1
Run Code Online (Sandbox Code Playgroud)
但它什么都没做.mof文件不会出现,也不会抛出任何错误消息.我错过了什么?
Configuration FileResourceDemo
{
Node "localhost"
{
File DirectoryCopy
{
Ensure = "Present" # You can also set Ensure to "Absent"
Type = "Directory" # Default is "File".
Recurse = $true # Ensure presence of subdirectories, too
SourcePath = "C:\Users\Public\Documents\DSCDemo\DemoSource"
DestinationPath = "C:\Users\Public\Documents\DSCDemo\DemoDestination"
}
Log AfterDirectoryCopy
{
# The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
Message = "Finished running the file resource with ID DirectoryCopy"
DependsOn = …Run Code Online (Sandbox Code Playgroud) 我需要快速的方法在bat文件中插入几行结构化数据我使用了一个名为myarray的数组来扫描和"读取"我的值,但它不起作用,我不明白为什么这是我的代码:
@echo off
set myarray[1]=myfield1#myfield2#mysubfield31;mysubfield32#myfield4
for /f "tokens=1-9 delims=#" %%a in ('echo %myarray[1]%') do (
echo field1 is %%a
echo field2 is %%b
echo field3 is %%c
echo field4 is %%d
for /f "tokens=1-9 delims=;" %%k in ('echo %%c') do (
echo subfield3 is %%k
echo subfield3 is %%l
)
)
Run Code Online (Sandbox Code Playgroud)
输出是这样的:
field1 is myfield1
field2 is myfield2
field3 is mysubfield31 mysubfield32
field4 is myfield4
subfield3 is mysubfield31 mysubfield32
subfield3 is
Run Code Online (Sandbox Code Playgroud)
为什么我不能简单地获得:
subfield3 is mysubfield31
subfield3 is mysubfield32
Run Code Online (Sandbox Code Playgroud)
哪里是 ";" …