Articles of PowerShell

将托pipe的registry文件推送到多个服务器

我有一堆服务器,我需要推这个补丁。 通常我会加载一个WSUS或同等的。 不过我想在DSC环境下工作。 所以我正在testing这个工作stream程的脚本。 PowerShell抱怨找不到文件夹。 Copy-Item $HostedRegFile -Destination $newfile "unauthorized" 显然我没有正确地传递凭据。 我已经尝试了所有我能想到的使用会话不使用会话.. $servers = Get-Content "d:\Powershell\Servers.txt" $Session = New-PSSession -computername $servers -credential $MyCredential $HostedRegFile = "\\Contra2\D:\reg\Player2.reg" foreach ($server in $servers) { #$Session = New-PSSession -computername $server -credential $MyCredential $newfile = "\\$server\c$\Utils\" New-Item -ErrorAction SilentlyContinue -ItemType directory -Path \\$server\C$\Utils\ Copy-Item $HostedRegFile -Destination $newfile Invoke-Command -computername $server […]

无法连接到Skype Online for Business – “winrm”问题

我试图通过LyncOnlineConnector PowerShell模块pipe理Skype Online for Business。 我没有任何连接远程交换的麻烦。 但是,我现在正在尝试使用New-CsOnlineSession而不是New-PSSession (用于连接到o365)完全相同的事情。 导入lync连接器工作正常。 但是,当我尝试构build会话(详细)时: VERBOSE: Determining domain to admin VERBOSE: AdminDomain = 'x.com' VERBOSE: Discovering PowerShell endpoint URI VERBOSE: TargetUri = 'https://admin1a.online.lync.com/OcsPowershellOAuth' VERBOSE: GET https://admin1a.online.lync.com/OcsPowershellOAuth with 0-byte payload VERBOSE: AuthUri = 'https://login.windows.net/common/oauth2/authorize' VERBOSE: Requesting authentication token VERBOSE: Success VERBOSE: Initializing remote session New-PSSession : [admin1a.online.lync.com] Connecting to remote server […]

icaclsvariables不能在PowerShell脚本中工作

我正在configuration一个运行在nanoserver 2016数据中心版上的新文件服务器。 现在我正在使用PowerShell脚本来创build用户文件夹。 但是在使用icacls命令设置权限时出现错误。 Enter-PSSession -Computername Test01 -Credential administrator $Domain = "MYDOMAIN" $user = Read-Host -Prompt 'Type in the username' $UD = $Domain +"\"+ $user E:\ mkdir e:\usernt\$user mkdir e:\usernt\$user\temp mkdir e:\usernt\$user\templates mkdir e:\usernt\$user\lotus\notes mkdir e:\usernt\$user\MyBar copy c:\MyBar e:\usernt\$user\MyBar New-SmbShare -Name $user$ -Path e:\usernt\$user Grant-SmbShareAccess -Name $user$ -AccountName Everyone -AccessRight full icacls e:\usernt\$user /T /C […]

在Amazon EC2中通过Powershell安装nginx

我有一个Amazon EC2实例。 我想在其上安装nginx web服务器。 我在Powershell(Windows 10)中build立了一个连接到服务器。 PowerShell截图我已经search,但还没有find答案。 我知道这可以在Linux中轻松完成,但我想在Windows中完成。 有没有办法做到这一点? 尝试安装Chocolaty,但看起来像巧克力作为PowerShell存储库源在EC2实例机器上不可用。 该实例是Windows Server 2016数据中心版本Nano。 我可以感觉到一些非常小的东西丢失了,但是却不知道是什么。

如何通过Powershell来了解在HyperV VM中运行的操作系统

所以这里是环境。 主持人:Windows 10 嘉宾:Server 2012和Server 2016 目的:在开发过程中自动将构build推送到服务器进行testing的开发系统。 我有一个Powershell函数作为这个完整的构build脚本的一部分,为我将要使用的VM获取远程PSSession。 由于虚拟机是从基本系统dynamic克隆的,在这一点上我不知道虚拟机的操作系统是什么。 如果是2016年的虚拟机,我宁愿使用Powershell Direct来连接虚拟机。 $session = New-PSSession -VMName $VMName -Credential $VMCredentials 如果是2012年,我必须回到networking上的WinRM会话。 我有代码来获取IP并build立连接。 它工作正常。 $vm = Get-Vm -Name $VMName $ips = New-Object System.Collections.Generic.List[System.String] foreach ($adapter in $vm.NetworkAdapters) { foreach ($ip in $adapter.IPAddresses) { if($ip -like '*.*') { $ips.Add($ip) } } } $session = New-PSSession -ComputerName $ips[0] -Authentication Negotiate […]

Set-msoluser:为什么“访问被拒绝”?

我有一个用户“rmuser”Azure帐户,我专门为自动closures虚拟机创build的。 该用户的密码已过期,所以虚拟机停止closures。 我手动更改了密码,以便帐户再次接受login。 我发现这一点,并开始通过它。 在这个过程中,我使用了Add-AzureAccount ,而不是接受订阅ID的Select-AzureSubscription ,而Get-AzureSubscription显示我正在使用正确的订阅。 我不得不为自己的帐户提供凭据,因为这是订阅的内容,但是我不能将这个帐户用于“Connect-MsolService”,因为它是在其他地方创build的,虽然我不明白,但我知道该帐户的处理与Azure中创build的帐户不同。 要获得“Connect-MsolService”的凭证,我在Get-Credential提示下给出了rmuser帐户名称和密码,并且在执行Connect-MsolService时没有发生错误。 所以我在正确的AD中,并且该用户具有全局pipe理员angular色。 但是,如果我调用Set-MsolUser ,则会收到错误Set-msoluser : Access Denied. You do not have permissions to call this cmdlet. Set-msoluser : Access Denied. You do not have permissions to call this cmdlet. 我以pipe理员身份明确运行Powershell。 我读过这个错误可能是由于指定的用户名没有被find,所以我用Get-MSOLUser确认用户被find了。 我也试过只更改Department字段,以防PasswordNeverExpires字段出现问题。 我在其他地方看过,执行策略可能是一个问题,所以我把它设置为无限制。 我有点难以接受下一步该做什么。 有谁知道发生了什么事,从哪里去?

使用读主机的子expression式

有人可以向我解释为什么这是行不通的? Get-Item "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" | Get-Item 写主机的行为完全如我所料… Write-Host "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" | Write-Host 另外,如果我手动提供string,它工作正常。 Get-Item "'\\computer\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" "'\\computer\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" | Get-Item 任何想法,为什么Get-Item想在这种情况下追加目标位置到当前位置? 提前致谢!

PowerShell脚本在Windows 10中运行,但不在Windows Embedded Standart上运行

我在Windows 10中有以下脚本工作,但不是在Windows 7上: $LogTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss" $Path1= "TEST\TESTLog_$(get-date -f yyyy-MM-dd).txt" $AffPBS= Get-Process "LLCService.exe" | Select-Object ProcessorAffinity $AffLC= Get-Process "LCService.exe" | Select-Object ProcessorAffinity $AffinityLLCFinal = "LLC " + $AffPBS $AffinityLCFinal = "LC " + $AffLC $FinalOutput = $LogTime+" " +$AffinityLLCFinal +" " + $AffinityLCFinal $FinalOutput | Out-File -Append $Path1 我已经以pipe理员身份运行Powershell_ISE,并设置了Set-ExecutionPolicy RemoteSigned。 我在Windows 10上得到的结果是: 10-09-2017_03-31-10 […]

授予Windows服务的权限

我还处于另一个障碍。 我有一个非pipe理员的IIS身份帐户,我想授予权限来启动,停止,重新启动和读取一个Windows服务的状态。 我遵循这里发布的解决scheme。 不过,我想通过PowerShell来实现这一点,因为我有这么多的服务器。 我能够获得非pipe理员帐号的SID,并获得命令的输出并将其保存在一个variables下。 我转换为string,但不能应用任何function,如StartsWith , split , insert等这里是我的代码: #Getting the SID for non-admin ISS identity account $objUser = New-Object System.Security.Principal.NTAccount("non-admin") $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) $sid = $strSID.Value #output retuned = S-1-5-21-2103278432-2794320136-1883075150-1000 #Storing the output of cmd prompt $cmd = cmd.exe /c "sc sdshow <Service_Name>" $test = $cmd | Out-String #output returned = D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD) #Storing […]

从AD用户获取顶级OU

我在问这个问题主要是问是否有更好的方式去做我的工作。 我也想知道是否有人通过这种方式看到这个信息的任何问题。 我正在尝试获取用户所在的顶级OU,以及任何较低级别的OU。 主要问题是我们有多个站点,其中一些站点有多个用户帐户的OU( ou=doctors,ou=Users,ou=Site,dc=example,dc=com ),有些站点只有一个单个OU( ou=Users,ou=Site,dc=example,dc=com )。 我使用下面的脚本获取DNpath,将其拆分,并用最后三个部分向后重build。 任何人都可以看到这样做的任何问题。 有些事情只是感觉错误…. $user = Get-ADUser CKnutson $user.DistinguishedName # Returns: CN=Cory Knutson,OU=IT,OU=Users,OU=Site,DC=example,DC=com $split = $user.DistinguishedName.Split(',') $path = "$($split[-3]),$($split[-2]),$($split[-1])" Write-Host $path # Returns: OU=Site,DC=example,DC=com 只是说明,最终的目标是让我走到我们刚才在每个“Site”OU里面的“Disabled”OU。 所以我的脚本可以移动对象,当禁用帐户到适当的地方,在该网站的顶级OU( OU=Disabled,OU=Site,DC=example,DC=com )。