我有一个 PowerShell 脚本,当直接输入到 PowerShell 中时它可以工作。PowerShell 程序使用快捷方式运行:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'"
Run Code Online (Sandbox Code Playgroud)
我在 Windows 任务计划程序中尝试了大约 10 种不同的方法来首先打开上面的快捷方式,然后运行我保存的脚本文件,但它不起作用。它挂在“正在运行”上。
该脚本位于此处:
Z:\Exchange PowerShell\MailboxesApproachingOverQuota.ps1
Run Code Online (Sandbox Code Playgroud)
请注意,可以将脚本内容复制并粘贴到上面的 PowerShell 快捷方式中,它运行得非常好,并将输出通过电子邮件发送给我。
请注意,我使用的 PowerShell 实例来自上面显示的快捷方式,其中已经包含参数 - 因此我很难过在 Task Scheduler 中放置什么内容。
请问有什么帮助吗?
谢谢 :)
编辑当我直接在 CMD 中使用以下内容时:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'; &'Z:\Exchange Powershell\MailboxesApproachingOverQuota.ps1'"
Run Code Online (Sandbox Code Playgroud)
我得到:http : //tinypic.com/r/n1fkmg/8
当我使用以下内容时:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'; &'Z:\Exchange Powershell\MailboxesApproachingOverQuota.ps1'"
Run Code Online (Sandbox Code Playgroud)
powershell exchange-2007 task-scheduler windows-sbs-2008 shell-scripting
在哪里可以找到命令-Path参数的详细说明New-ADUser?
我想指定一个相当详细的路径,而不需要Set-Location多次调用来指定我希望用户创建的位置。
我编写了一个 powershell 脚本,它从一个 OU 中获取所有组并将它们存储在变量 $groups 中。我希望能够访问每个组的用户,但似乎遇到了问题。我试过了:
foreach($group in $groups){$get-ADUser $group}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:33
+ foreach($group in $groups){$get- <<<< ADUser $group}
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
Run Code Online (Sandbox Code Playgroud)
我在 Windows 7 机器上使用 Windows Server 2003 R2。我对此很陌生,因此非常感谢任何帮助。
我想在启动时运行 powershell 脚本,但对话框上没有“powershell”选项卡。
我正在运行 Windows Server 2008 64 位。
谢谢!
有没有将 PowerShell v3 脚本的输出强制为表格形式?我的脚本以线性形式输出服务列表,即使输出对象中只有 6 个字段(get-process 以表格形式输出 8 个字段)。这是我的代码:
<#
.SYNOPSIS
Gets a list of services on a given computer that are supposed to automatically start but are not currently running.
.PARAMETER ComputerName
The computer name(s) to retrieve the info from.
.PARAMETER IgnoreList
The path and filename of a text file containing a list of service names to ignore. This file has to list actual service names and not display names. Defaults to "StoppedServices-Ignore.txt" in the current directory.
.PARAMETER StartServices …Run Code Online (Sandbox Code Playgroud) 一直在努力解决这个问题,想知道是否有人可以提供帮助。我有一个很大的文本文件,里面有我想删除的额外数据。这是输入文件的示例:
Text In Page - 1
S
Dept
l<m RKB)
"1915
slightly 234234
"sil dsf 56
"gr
gl
1920 100
1925 100
1930 100 Cls
"1935 100 Cl
Text In Page - 2
l<m RKB)
"1915
slightly
"sil
"gr
glauc
1920 100
1925 100
1930 100 Cls
"1935 100 Cl
Run Code Online (Sandbox Code Playgroud)
我想删除以下内容:
所以有了上面的例子,我就剩下
1915
1920 100
1925 100
1930 100 Cls
1935 100 Cl
1915
1920 100
1925 100
1930 100 Cls
1935 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 powershell 将员工列表导入 AD。该脚本需要更新现有的 AD 对象。
我遇到的问题是,有些用户会有手机号码,有些是内部号码,有些只是扩展名,当我以最基本的形式运行 Set-ADuser 命令时,只要值为空,它似乎就会失败。
我不擅长脚本,谁能向我解释为什么下面的脚本不起作用?如果是这样,有人可以建议如何使其工作吗?干杯
Import-module ActiveDirectory
$CSVPath = "c:\scripts\ictdepartment2.csv"
$csvData = Import-CSV $CSVPath -delimiter "," -Header ("SamaccountName","identity","Title","Company","Department","Description","Office","OfficePhone","IPPhone","MobilePhone")
##
foreach ($line in $csvData)
{
$accountTable = @{
'SamaccountName'= $line.SamaccountName
'identity'= $line.identity
'title'= $line.title
'company'= $line.company
'department'= $line.department
'description'= $line.description
'office'= $line.office
'officephone'= $line.officephone
'IPPhone'= $line.ipPhone
'mobilephone'= $line.mobilephone
}
}
##
ForEach($line in $csvData)
{
$SamaccountName = $line.SamaccountName
$identity = $line.identity
$title = $line.title
$company = $line.company
$department = $line.department
$description = $line.description
$office = $line.office …Run Code Online (Sandbox Code Playgroud) 我正在开发用于活动目录监控的 sysvol 检查脚本。完成了在给定域中的所有域控制器上检查与 sysvol 连接的脚本。作为其中的一部分,我正在做以下检查
Start-Job -sb "(Measure-Command{Dir \\$DCName\sysvol\$Domain\Policies}).Milliseconds"
Run Code Online (Sandbox Code Playgroud)
这将返回以毫秒为单位的时间;不幸的是,由于明显的原因,即使 sysvol 无法访问,它也会返回时间,并且与可访问相比,它甚至更快。
我的问题是当我收到工作时,有没有办法找出工作是否有错误?因为测量命令并没有给出全貌。如果有任何其他关于此的问题,请告诉我。
windows powershell active-directory sysvol windows-server-2012-r2
尝试用他们自己的 samaccountname 替换所有用户的 mailNickname:
Import-Module activedirectory
$SAM = (Get-ADUser -SearchBase "OU=Staged,OU=corp,DC=mycompany,DC=com" -Filter * | select samaccountname)
foreach ($User in $SAM.samaccountname)
{
Set-ADUser $User -Replace @{mailNickName = "$SAM"}
}
Run Code Online (Sandbox Code Playgroud)
此脚本将 mailNickName 设置为空白。任何的想法?谢谢
我有一个 CMD 文件,我必须从中运行一个传入用户名和密码的 Powershell 脚本:即:PowerShell -File "%1" -Computer "%2" -Username "%3" -Password "%4"。反正有没有将 SecureString 密码从 CMD 发送到 powershell 脚本?
让我再补充几点,让我的困境更加清晰:所以每当我执行这个包含上述 Powershell 命令的 CMD 文件时,我都会在命令行上传递所有参数(%1% 到 %4%)的值. 现在,当我传递这些参数时,它们以明文形式传入,并且所有内容都记录到事件监视器中,ID 为 4688 且启用了高级审计。我想要的是密码在这种情况下不可见。