我正在将我的PowerShell_ISE配置文件功能转换为VS Code中的代码段。该代码的一部分是向脚本添加标头。我想从活动目录中获取用户名,并将其放在标题中的注释中。我们的登录ID是随机生成的。所以我希望做这样的事情:
<tr class="category motherboard" data-value="motherboard">
<td>
<span>Motherboard</span>
</td>
<td>
<select name="motherboard" id="motherboard" style="min-width: 100%;" class="select" onchange="getPrice(event)">
<option>Select Motherboard</option>
<?php echo motherboard_brand($connect); ?>
</select>
</td>
<!-- QUANTITY -->
<td>
<input type="number" min="0" name="email" class="quantity" oninput="setTotalPrice(event)"/>
</td>
<!-- per item price -->
<td>
<input type="text" readonly class="unit-price" >
</td>
<!-- Total Price -->
<td>
<input type="text" readonly class="total-price">
</td>
</tr>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
function getPrice(e){
e.preventDefault();
grandtotal();
var id = $(e.target).val();
// console.log(id);
let parent = e.target.parentNode.parentNode;
// console.log(parent);
let category = parent.getAttribute("data-value");
// console.log(category);
$.ajax({
url:"load_data.php",
method:"POST",
data:{id:id},
success:function(data){
// console.log(id);
let unitPrice = parent.querySelector("input.unit-price");
// console.log(unitPrice);
unitPrice.value = data;
$(parent).attr("data-id", id);
$(parent).attr("data-quantity", 1);
parent.querySelector("input.quantity").value = 1;
parent.querySelector("input.total-price").value = +data * 1;
grandtotal();
}
});
}
function setTotalPrice(e){
e.preventDefault();
// console.log(event.target);
let parent = e.target.parentNode.parentNode;
// console.log(parent);
let unitPrice = parent.querySelector("input.unit-price").value;
let quantity = parent.querySelector("input.quantity").value;
$(parent).attr("data-quantity", quantity);
parent.querySelector("input.total-price").value = (+unitPrice) * (+quantity);
grandtotal();
}
// Grand Total
function grandtotal() {
var sum=0;
$('.total-price').each(function(){
var item_val=parseFloat($(this).val());
if(isNaN(item_val)){
item_val=0;
}
sum+=item_val;
$('#TotalPrice').html(sum.toFixed(2));
});
}
</script>
问题是代码段插入了代码而不是值。我确实发现在VS Code中您访问环境变量有些不同,因此我尝试了这一点。
#(Get-AdUser $Env:username -Properties DisplayName).DisplayName
但这会产生以下输出:
#(Get-AdUser ${env:username} -Properties DisplayName).DisplayName
有人可以帮我解决这个问题吗?
我需要它来提取env:username变量,然后使用它来查询Active Directory中的用户显示名。