小编use*_*272的帖子

Powershell 日期时间空值

我正在开发一个关于 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)

powershell datetime active-directory

2
推荐指数
1
解决办法
254
查看次数

如何在一行中获取 Windows 批处理文件输出中的 PowerShell 命令和命令 ECHO 的输出?

以下命令行在 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 …

powershell datetime cmd batch-file echo

1
推荐指数
1
解决办法
216
查看次数

标签 统计

datetime ×2

powershell ×2

active-directory ×1

batch-file ×1

cmd ×1

echo ×1