执行批处理文件不会检索信息并将其保存在.txt中

时间:2017-05-04 12:58:29

标签: windows powershell batch-file

所以我试图在文本文件中获取新注册用户的信息。

我来到这个剧本:

uses
  Windows, MultiMon, Math;

procedure ClipOrCenterRectToMonitor(var Prc: TRect; var Flags: UINT);
var
  hMon: HMONITOR;
  mi: MONITORINFO;
  Rect: TRect;
  w, h: Integer;
const
  MONITOR_CENTER  =   $0001;        // center rect to monitor
  MONITOR_CLIP  =   $0000;        // clip rect to monitor
  MONITOR_WORKAREA = $0002;        // use monitor work area
  MONITOR_AREA  =  $0000;        // use monitor entire area

begin
  w := Prc.Right - Prc.Left;
  h := Prc.Bottom - Prc.Top;

  hMon := MonitorFromRect(@Prc, Flags);

  mi.cbSize := SizeOf(mi);
  GetMonitorInfo(hMon, @mi);
  if (flags and MONITOR_WORKAREA) <> 0 then
    Rect := mi.rcWork
  else
    Rect := mi.rcMonitor;
  if (flags and MONITOR_CENTER) <> 0 then
  begin
    Prc.Left := Rect.Left + (Rect.Right - Rect.Left - w) div 2;
    Prc.Top := Rect.Top + (Rect.Bottom - Rect.Top - h) div 2;
    Prc.Right := Prc.Left + w;
    Prc.Bottom := Prc.Top + h;
  end
  else
  begin
    Prc.Left := Max(Rect.left, Min(Rect.Right - w, Rect.Left));
    Prc.Top := Max(Rect.Top, Min(Rect.Bottom - h, Rect.Top));
    Prc.Right := Prc.Left + w;
    Prc.Bottom := Prc.Top + h;
  end;
end;

procedure ClipOrCenterWindowToMonitor(Wnd: HWND; Flags: UINT);
var
  Rect: TRect;
begin
  GetWindowRect(Wnd, Rect);
  ClipOrCenterRectToMonitor(Rect, Flags);
  SetWindowPos(Wnd, 0, Rect.Left, Rect.Top, 0, 0, SWP_NOSIZE or SWP_NOZORDER or SWP_NOACTIVATE);
end;

如果我在powershell中执行它,它可以工作,但如果我尝试从.bat文件执行此操作,则.txt文件为空,没有关于用户的信息。

这与&#34; $当&#34;变量?

1 个答案:

答案 0 :(得分:0)

您可以跟踪以创建包含以下内容的.bat文件:

Powershell.exe -command "$When = ((Get-Date).AddDays(-15)).Date;Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated  | Export-Csv d:\temp\u.csv"