在命令中使用变量 (PowerShell) [英] Using a Variable (PowerShell) inside of a command

查看:69
本文介绍了在命令中使用变量 (PowerShell)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$computer = gc env:computername

# Argument /RU '$computer'\admin isn't working.
SchTasks /create /SC Daily /tn "Image Verification" /ST 18:00:00 /TR C:\bdr\ImageVerification\ImageVerification.exe /RU '$computer'\admin /RP password

基本上我需要在计划任务中提供计算机名称...

Basically I need to provide the computer name in the scheduled task...

先谢谢你!

推荐答案

单引号字符串不会在 PowerShell 中扩展变量.尝试使用双引号字符串,例如:

Single quoted strings will not expand variables in PowerShell. Try a double quoted string e.g.:

"$computer\admin"

这篇关于在命令中使用变量 (PowerShell)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆