Articles of PowerShell

Get-AutomationPSCredential在Azure自动化中间歇性失败

每隔一段时间,我们都会发现Azure自动化Runbook失败,并显示以下错误: Get-AutomationPSCredential : The term 'Get-AutomationPSCredential' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:9 + $cred = Get-AutomationPSCredential -Name SqlJobRunner + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo […]

计划任务中的PowerShell脚本错误

我在多台服务器上运行两个PowerShell脚本作为计划任务。 一个脚本(#1)将文件夹从一个应用程序移动到另一个文件夹(垃圾),另一个脚本(#2)重新启动服务。 脚本#1将文件夹复制到目标path,然后删除源path中的文件夹。 该脚本在PowerShell控制台中手动运行时工作,但作为计划任务运行时,它不会将文件夹复制到目标path,但会删除源path中的文件夹。 脚本#2在两台服务器上重新启动MySQL和IIS,但通常无法在第三台服务器上重新启动MSSQL。 当我检查计划任务历史logging时,脚本运行30分钟,然后被调度程序强制停止。 它重新启动一个MSSQL实例,所以最多只需要几分钟时间。 这两个脚本都使用-ExecutionPolicy Bypass和最高权限运行,Start In文件夹设置为其安装path。 历史logging中的操作代码出现错误(2)。 这是找不到文件的消息。 每个脚本都使用XML文件进行设置。 有没有人有任何想法,我可能会失踪的脚本运行无人值守? 谢谢。

尝试使用Mount-WindowsImage cmdlet装入install.wim文件时出现“拒绝访问”错误

当我尝试安装一个Windows映像来应用更新,以便我可以使用WDS进行批量部署时,出现拒绝访问错误。 以下是我运行的命令的一个示例,以及Windows Server 2012 R2 Datacenter操作系统向我发出的错误。 Mount-WindowsImage -ImagePath "F:\sources\install.wim" -Path "D:\MountPoint" -Index 2 Mount-WindowsImage : You do not have permissions to mount and modify this image. Verify that you have Read/Write permissions or mount the image using the /ReadOnly option. Note that you cannot commit changes to an image with read-only permissions. 我正在尝试安装的映像是Windows 8.1 Pro映像。 […]

Powershell – 检查文件是否是Linux符号链接

我正在迁移基于NetApp NTFS的文件系统。 它安装在Windows和Linux上。 我在Powershell中的validation脚本是走文件系统,并进行各种检查,源和目标是相同的。 它例如检查时间戳和校验和。 它还使用get-acl的sddl属性比较ACL。 但是,其中一些文件实际上是Linux符号链接。 在这种情况下,一切正常,但get-acl调用会引发错误 Get-Acl:试图执行未经授权的操作。 在这种情况下,安全性确实在链接目标上,所以我不需要检查它。 然而,我不知道如何跳过检查这些文件,因为我不知道如何检测到他们是Linux的符号链接。 有没有办法检测到一个文件是一个Linux的符号链接,以便我可以跳过get-acl检查?

Office365审计 – 专门查看login到帐户的设备

我们有一些客户与政府合同工作,他们的一些要求是能够审计帐户,并根据IP查看他们login的位置。 有没有办法做到这一点? 我试图通过PowerShell,但我不知道这是否是要走的路。 Get-Mailbox -ResultSize Unlimited -Filter {RecipientTypeDetails -eq "UserMailbox"} | Set-Mailbox -AuditEnabled $true 并观看: Get-Mailbox -ResultSize Unlimited -Filter {RecipientTypeDetails -eq "UserMailbox"} | Set-Mailbox -AuditOwner MailboxLogin 我是否正在以正确的方式查看带有时间戳的IP,何时login以及使用哪些设备?

如何生成上一次每个域用户login到特定的Windows Server 2008虚拟机的报告?

我有一个Windows服务器2008 R2 vm,它有近4800个域用户在过去的三年中login过。 编号喜欢生成一个报告,列出用户名称以及他们上次login到这个特定的虚拟机。 我通过search遇到的所有内容都是login到vm的最后一个用户,或者跨域的最后一个login时间。 我无法find一种方法来生成用户名列表,最后一次login到特定的虚拟机。 任何帮助?

psexec仅在使用用户名和密码并从PowerShell脚本调用时挂起

我正在尝试使用psexec在已打开的交互式会话中启动进程。 我的机器和远程机器都是Windows 7.使用命令提示符内的命令可以正常工作,可执行文件已启动,并在GUI中可见。 psexec64 -accepteula -nobanner \\hostname -u domain\user -p password -h -i 2 -d C:\workingdir\subfolder\application.exe 但是,当我尝试在PowerShell脚本中执行相同的调用时,它不起作用。 查看完整脚本的上下文。 # invalid args: $psExecArgs = "-accepteula", "-nobanner", "-u domain`\${username}", "-p ${password}", "-h", "-i ${sessionId}", "-d", "`\`\${hostname}", "`"${executableDirectory}`\${executableName}`"" # hangs: $psExecArgs = "-accepteula", "-nobanner", "-u domain`\${username}", "-p ${password}", "-h", "-d", "`\`\${hostname}", "`"${executableDirectory}`\${executableName}`"" $psExecArgs = "-accepteula", "-nobanner", "-h", "-d", […]

如何在PowerShell中扩展这个属性

我试图扩大会员财产在PowerShell的whithout成功:( 这是我的代码… Import-Module ActiveDirectory Get-ADGroup -Filter * -Properties * | Select-Object -Property Name, Description, GroupCategory,` @{Name='Members';exp={Get-adgroupmember $_.Name | Select -Expand Name |Select}} | format-list -Property Name, Members, Description, GroupCategory 会员属性,我想扩大

使用PowerShell通过CSV分配NTFS权限

我有一个CSV文件如下 文件夹名称 ———- 安全组 Folder1 ———- SG_Folder1-Access Folder2 ———- SG_Folder2-Access 我需要像下面这样分配权限, 所以安全组“SG_Folder1-Access”将修改“文件夹1”的访问权限 安全组“SG_Folder2-Access”将修改“文件夹2”的访问权限 我有500个文件夹和他们自己的安全组,需要创build一个权限shell脚本来分配权限。 任何帮助将非常感激。 谢谢

在使用psexec远程启动PowerShell脚本时,Jenkins作业中的输出被截断

我在Jenkins创build了一个工作,使用psexec在远程机器上启动一个小的powershell脚本。 在我的构build步骤中,我正在使用powershell插件并启动以下命令: & "$env:SCRIPTROOT\test_psexec.ps1" -Username $env:USERNAME -Password $env:PASSWORD -Server $env:REMOTESERVER 在test_psexec.ps1文件中,我有下面的代码: $filePath = "C:\windows\temp\test_script.ps1" $server = "server01" $cmd = "powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass -File $filePath" Write-Host "Launching powershell on remote system using psexec…" Write-Host "Command: & $PSScriptRoot\tools\psexec -accepteula -nobanner -u $username -p **** -h \\$server $cmd" $output = & $PSScriptRoot\tools\psexec -accepteula -nobanner -u $username […]