我正在尝试使用 Powershell 获取 Windows 系统的所有驱动器号,但我无法弄清楚。有任何想法吗?
我曾尝试使用Get-Volume,但它没有用于-ByDriveType或-ByType或-Type或任何东西的参数。
我有一个 azure 订阅,其中有超过 200 个 appServices,其中大约一半有连续的,总是在附加的 webJobs 上,有些也有插槽,也有 webJobs。
有没有办法列出订阅中的所有 web 作业?我最初尝试使用 powershell 来执行此操作,但它变得相当复杂,并且想知道是否有人知道实现上述目标的简单方法。
似乎 Get-AzureRmWebApp 应该能够提供帮助,但我找不到列出驻留在 webapp 中的作业的方法。
powershell azure azure-resource-manager azure-web-app-service
我想在 powershell 中创建一个多维数组,如下所示:
$array[0] = "colours"
$array[0][0] = "red"
$array[0][1] = "blue"
$array[1] = "animals"
$array[1][0] = "cat"
$array[1][0] = "dog"
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
$array = @()
$array += "colours"
$array += "animals"
$array[0] # outputs "colours"
$array[1] # outputs "animals"
$array[0] = @()
$array[1] = @()
$array[0] += "red"
$array[0] += "blue"
$array[1] += "cat"
$array[1] += "dog"
$array[0] # outputs "red", "blue" - i expected "colours" here
$array[0][0] # outputs "red"
Run Code Online (Sandbox Code Playgroud)
我很欣赏任何提示。
提前致谢
我很难弄清楚这一点,我有以下 powershell 脚本,简单的一个:
$BambooPath = 'C:\StartFolder\*'
$RemoteWebPath = 'C:\DestFolder'
Copy-Item -Path $BambooPath -Destination $RemoteWebPath -Recurse
Run Code Online (Sandbox Code Playgroud)
我不想在 $BambooPath 中用 ${bamboo.build.working.directory}* 变量替换 C:\StartFolder* ......有人知道怎么做吗?
我想从这个脚本中排除禁用的用户,但似乎无法找到我如何尝试 -exclude 没有运气。
如果你也有更好的方法来公开建议
import-module ActiveDirectory;
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
Get-ADUser -filter * -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, GivenName | foreach {
$today=get-date
$UserName=$_.GivenName
$Email=$_.EmailAddress
if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) {
$ExpiryDate=$_.PasswordLastSet + $maxPasswordAgeTimeSpan
$DaysLeft=($ExpiryDate-$today).days
if ($DaysLeft -lt 10 -and $DaysLeft -gt 0){
$WarnMsg = "
<p style='font-family:arial'>Bonjour $UserName,</p>
<p style='font-family:arial'>Votre mot de passe va expirer dans $DaysLeft jours, S.V.P. changer votre mot de passe.</p>
<p style='font-family:arial'>Merci.</p>"
$enc = New-Object System.Text.utf8encoding
ForEach ($email in $_.EmailAddress) {
send-mailmessage -to test@test -from noreply@test.com -Subject …Run Code Online (Sandbox Code Playgroud) 在 SO 上多次问过类似的问题,通常答案是以下之一:
cmd然后命令cmd传递/c以及我已经尝试过的其他一些事情。但我的问题是:我有一个拒绝在 PowerShell 上运行的特定程序 ( cntkpy34.bat) 。也就是说,使用上述任何解决方案,我仍然会收到“请从常规 Windows 命令提示符中执行此脚本”。
所以我真正想要的是调用一个新cmd.exe窗口并在其上运行命令。如何在 PowerShell 脚本中实现这一点?
编辑:检查批处理文件,这是它验证外壳的方式:
if /I "%CMDCMDLINE%" neq ""%COMSPEC%" " (
echo.
echo Please execute this script from inside a regular Windows command prompt.
echo.
exit /b 0
)
Run Code Online (Sandbox Code Playgroud)
即使开始一个新的cmd.exe过程也不会这样做。
可以在 PowerShell 中定义脚本的输出类型。考虑myScript.ps1:
[OutputType([String])]
param(
[string]$name
)
Run Code Online (Sandbox Code Playgroud)
以下返回String:
(Get-Command .\myScript.ps1).OutputType.Name
Run Code Online (Sandbox Code Playgroud)
但我想指定脚本返回text/json或text/xml. 这样做的好方法是什么?
为 OutputType 发明类型(例如[String.JSON])不起作用。
我使用PowerShell的扩展为Visual Studio代码。我更新了个人资料:
C:\Users\xxxxxxxx\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1
包含一些我想让其他脚本使用的函数和变量。当我从另一个脚本中的配置文件中引用变量时,似乎没有加载配置文件。我怀疑这是因为当我从 VS Code 控制台查询时变量值为空。如果我从具有关联配置文件的标准 Powershell 控制台运行相同的测试,则解析变量值。
谁能告诉我在调试时我需要做什么才能在 VS Code 中使用 Powershell 配置文件?
我有一个简单的问题,但我找不到任何答案。
我正在使用 powershell 5 并且我在封闭环境中工作,无法连接到互联网,我想在我的机器上手动安装模块,基本上是任何可以下载的模块,例如 posh-ssh。
可以做到吗?让我们说在此处保存模块并安装?
如何通过 PowerShell 在 IIS 中设置应用程序设置?
我尝试使用Set-WebConfigurationProperty作为
Set-WebConfigurationProperty "/appSettings/add[@key='someKey']" -PSPath "IIS:\Sites\Default Web Site\someSite" -name "someKey" -Value "someValue"
Run Code Online (Sandbox Code Playgroud)
但我越来越
WARNING: Target configuration object '/appSettings/add[@key='someKey'] is not found at path 'MACHINE/WEBROOT/APPHOST/Default Web Site/someSite'.
Run Code Online (Sandbox Code Playgroud) powershell ×10
azure ×1
bamboo ×1
batch-file ×1
cmd ×1
disk ×1
iis ×1
reflection ×1
windows ×1