我正在开发一个关于 AD 用户帐户到期日期的 powershell。但是我遇到了一个问题,无法通过空参数将 AD 用户帐户到期日期设置为 NEVER。
请帮忙!谢谢。
https://i.stack.imgur.com/Zt8sv.png
下面是我的脚本。
import-module C:\PS\color_menu.psm1
CreateMenu -Title "AD User Account Expire Tools" -MenuItems "View the User Account Expire Date","Set the User Account Expire Date","Exit" -TitleColor Red -LineColor Cyan -menuItemColor Yellow
do {
[int]$userMenuChoice = 0
while ( $userMenuChoice -lt 1 -or $userMenuChoice -gt 3) {
Write-Host "1. View the User Account Expire Date"
Write-Host "2. Set the User Account Expire Date"
Write-Host "3. Exit"
[int]$userMenuChoice = Read-Host "Please choose an option"
switch ($userMenuChoice) …Run Code Online (Sandbox Code Playgroud) 以下命令行在 Windows 批处理文件中不起作用:
Powershell.exe -Command Get-Date -Format 'yyyy-MM-dd HH:mm:ss' echo "Hello World"
Run Code Online (Sandbox Code Playgroud)
预期结果为:2021-05-09 12:00:00 Hello World
但是 PowerShell 输出错误消息:
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "echo" to type "System.DateTime".
Error: "The string was not recognized as a valid DateTime. There is a unknown word starting at index 0."
At line:1 char:9
+ Get-Date <<<< -Format 'yyyy-MM-dd HH:mm:ss' echo Hello World
+ CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
Run Code Online (Sandbox Code Playgroud)
如何获取 PowerShell 命令的输出以获取格式的日期和时间yyyy-MM-dd HH:mm:ss …