小编Mat*_*att的帖子

通过PowerShell获取Azure VM详细信息

我正在尝试运行Get-AzureVMPowerShell命令,它运行正常但不返回任何输出.

还尝试了以下风味,但仍然空白结果任何想法?

Get-AzureVM -Name "vmname" |Select-Object name,instancesize,location
Run Code Online (Sandbox Code Playgroud)

powershell azure powershell-3.0

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

PowerShell将命名参数传递给ArgumentList

我有一个PowerShell脚本,它接受3个命名参数.请让我知道如何从命令行传递相同的内容.我尝试下面的代码,但同样不起作用.它仅将整个值分配给P3.我的要求是P1应该包含1,P2应该包含2,而P3应该包含3.

Invoke-Command -ComputerName server -FilePath "D:\test.ps1" -ArgumentList  {-P1 1 -P2 2 -P3 3}
Run Code Online (Sandbox Code Playgroud)

以下是脚本文件代码.

Param (
    [string]$P3,
    [string]$P2,
    [string]$P1
)
Write-Output "P1 Value :" $P1
Write-Output "P2 Value:" $P2
Write-Output "P3 Value :" $P3
Run Code Online (Sandbox Code Playgroud)

parameters powershell command invoke named

10
推荐指数
2
解决办法
2万
查看次数

当.visible = $ false时,Powershell excel刷新失败并且"Call被Callee拒绝"

我已经有很长一段时间没有这个问题而且只是因为懒惰而忽略了它,但我现在需要找到一个解决方案.我有一个脚本可以自动刷新大量的Excel文档.这很好用,但是,如果我将Visible属性设置为false,则存储在网络共享上的工作簿上会失败.

重申一下,使用设置为false的visible属性刷新在LOCAL文件上工作正常,但保存在\ location上的任何工作簿都会失败,并显示错误"调用被被调用者拒绝".所有刷新工作正常,可见属性设置为true.

这是我的代码:

#Create Excel COM object and set it up for use.
$excel = new-object -comobject Excel.Application;
$excel.DisplayAlerts = $false;
#If this is set to false, saving the file on a network share will fail. Reason : Unknown.
$excel.Visible = $true;
#Open workbook which should be refreshed. 
$excelworkbook = $excel.workbooks.Open($workbook);
#Refresh WB
$excelworkbook.RefreshAll();
#Save
$excelworkbook.Save();
#Quit Excel
$excel.Quit();
#Destroy COM object. (VERY IMPORTANT!!!!!)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel);
Run Code Online (Sandbox Code Playgroud)

我尝试过以下方法:

  1. 在创建excel对象和设置visible属性之间添加Start-Sleep 30
  2. 在DisplayAlerts之前设置可见
  3. 希望它能够真正发挥作用

有任何想法吗?

com excel powershell

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

如何存储Format-Table的输出以供以后使用

我有一个脚本可以创建多个作业并在作业中存储两个简单的值.

Start-Job -ScriptBlock {param ([string]$compip) tnc $compip | select RemoteAddress,PingSucceeded -WarningAction SilentlyContinue} -ArgumentList $compip
Run Code Online (Sandbox Code Playgroud)

这很好用.我想知道的是如何将以下代码存储到变量中?

Get-Job | Receive-Job | sort RemoteAddress | FT
Run Code Online (Sandbox Code Playgroud)

我试过这个,但它没有像我想的那样工作:

$pcs = Get-Job | Receive-Job | sort RemoteAddress | FT
$pcs.RemoteAddress
Run Code Online (Sandbox Code Playgroud)

我是以错误的方式去做的吗?我想存储get-job上面命令中的数据,以便稍后在脚本中使用这些值.我认为它会工作,因为输出看起来正确:命令:

Get-Job | Receive-Job | sort RemoteAddress | FT
Run Code Online (Sandbox Code Playgroud)

输出:

RemoteAddress PingSucceeded                        
------------- -------------                         
192.168.0.163          True
192.168.0.101          False
192.168.0.2            False
192.168.0.251          True 
Run Code Online (Sandbox Code Playgroud)

powershell

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

无法从PowerShell运行elixir应用程序

当我输入iex -S mixPowerShell时,我收到此错误:

Invoke-Expression : A positional parameter cannot be found that accepts argument 'mix'.
At line:1 char:1
+ iex S mix
+ ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Run Code Online (Sandbox Code Playgroud)

在'iex'命令之后编写'-S mix'以获得在cmd中输入相同效果的正确方法是什么?我不相信PowerShell语法,这是一个问题.

powershell elixir

8
推荐指数
2
解决办法
1304
查看次数

获取特定OU及其子OU中的用户数

我正在寻找一个能让我获得的PowerShell脚本:

  1. 的名字 OU's
  2. 每个AD用户数的计数OU.

我发现了这个:

(Get-ADUser -Filter * -SearchBase “ou=Users,ou=A1,dc=contoso,dc=com”).count
Run Code Online (Sandbox Code Playgroud)

这正是我想要的,但我必须输入每个OU名字.问题是我们有100多个OU's.具体OU我想要运行它是contoso.com\cmsg\userscmsg\users100+ OU's所在的地方.

powershell active-directory

7
推荐指数
1
解决办法
6万
查看次数

当"Select-Object -First"出现时,如何解释不工作"Tee-Object"

使用以下代码,$t等于@(1,2).

$t = "before"
1..2 | Tee-Object -Variable t
Run Code Online (Sandbox Code Playgroud)

那么为什么下一个代码片段$t等于"before"而不是@(1)*?

$t = "before"
1..2 | Tee-Object -Variable t | Select-Object -First 1
Run Code Online (Sandbox Code Playgroud)

我在Powershell版本5和版本3中看到了相同的结果.

powershell pipeline powershell-3.0 powershell-5.0

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

找到与字符串或部分字符串匹配的所有子目录

我基本上需要在不知道完整路径的情况下将变量设置为文件夹路径.

我的问题是我需要找一个名为"DirA"的目录.但是这个目录可能位于"DirB \"或"DirB\DirC"中,有时它们可​​能包含的目录名称也不相同.

我知道目录路径的第一部分将是相同的,所以我想到使用-recurse过滤器到文件夹名称,但有时我正在寻找的目录不像通常预期的那样,有时是额外的最后的信.

是否有可能做某事......

$MyVariable = Get-ChildItem D:\Data\Dir1 -Recurse | Where-Object {$_.name -like "name"} -Directory |
% { $_.fullname }
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏!

filesystems powershell powershell-2.0 get-childitem

7
推荐指数
2
解决办法
2万
查看次数

以管理员身份运行 PS,但收到错误 - 该操作需要提升

由于各种新的安全策略,我们需要能够作为分配的 uid 运行各种任务。为了帮助实现这一点,开发了一个通用菜单系统。脚本中的函数之一是:

$credential = user_credential
$cmd = "C:\windows\system32\mmc.exe" 
$args = "C:\Windows\System32\compmgmt.msc"
Start-Process -FilePath $cmd -ArgumentList $args  -Credential $credential
Run Code Online (Sandbox Code Playgroud)

收到错误:

Start-Process : This command cannot be run due to the error: The requested operation requires elevation.
t C:\webeng\webeng.ps1:131 char:5
     Start-Process -FilePath $cmd -ArgumentList $args  -Credential $credential
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
   + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Run Code Online (Sandbox Code Playgroud)

该错误似乎表明 PS 脚本需要提升权限,但我已经以管理员身份运行。

我在这里可能会错过什么?

powershell credentials invalidoperationexception

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

Azure PowerShell无法连接

我按照MS说明下载并安装了Azure Powershell:https: //azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/

使用Windows Powershell ISE我运行命令:

登录-AzureRmAccount

返回错误:

Login-AzureRmAccount : The 'Login-AzureRmAccount' command was found in the module 'AzureRM.Profile', but the  module could not be loaded. For more information, run 'Import-Module AzureRM.Profile'. At line:1 char:1
+ Login-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Login-AzureRmAccount:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
Run Code Online (Sandbox Code Playgroud)

导入模块AzureRM.Profile

返回此错误:

Import-Module : File C:\Program Files (x86)\Microsoft 
SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Profile\CheckVersions.ps1 cannot be loaded 
because running scripts is disabled on this system. For more information, see about_Execution_Policies at 
http://go.microsoft.com/fwlink/?LinkID=135170.
At …
Run Code Online (Sandbox Code Playgroud)

powershell azure azure-powershell

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