我正在使用以下内容来创建密码文件:
$path = "C:\Users\USER\Desktop"
$passwd = Read-Host "enter desired password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd
$encpwd > $path\filename.bin
Run Code Online (Sandbox Code Playgroud)
然后使用以下命令调用文件:
# define path to store password and input password
$path = "C:\Users\USER\Desktop"
# get the encrypted password from the path
$encpwd = Get-Content $path\filename.bin
# convert file to secure string
$passwd = ConvertTo-SecureString $encpwd
# define needed credential
$cred = new-object System.Management.Automation.PSCredential 'WIN-SERVER\AdminForQB',$passwd
# go to DVD drive launch setup.exe as user with privileges to launch the program with no user …Run Code Online (Sandbox Code Playgroud) 希望对过滤器选项有更好的了解,例如
这产生了适当的结果
Get-WmiObject -Class Win32_Service -Filter "Name = 'vss'"
Run Code Online (Sandbox Code Playgroud)
如何在过滤器内部进行通配符搜索而不将其管道传递到where条件,例如:
Get-WmiObject -Class Win32_Service -Filter "Name='v*'"
Get-WmiObject -Class Win32_Service -Filter "Name='*v*'"
Get-WmiObject -Class Win32_Service -Filter "Name='v'"
Get-WmiObject -Class Win32_Service -Filter "Name like 'v*'"
Run Code Online (Sandbox Code Playgroud) 以这样的命令为例:
Get-AdUser -Filter {Enabled -eq $true} -Credential (Get-Credentials) -Server some.server.domain.com | Where-Object {DisplayName -like '*Reemer, Bob*'}
Run Code Online (Sandbox Code Playgroud)
当然它是粗略的,长的并且离开屏幕...在多行上分割这个(提高可读性)的首选方法是什么?
请提供适用于ISE,简单PowerShell解释器和脚本的示例.
想象一下,我们有一个可以获取密码(或其他敏感信息)参数的程序或脚本:
> program.exe /password:secret
Run Code Online (Sandbox Code Playgroud)
对于Linux,最佳实践通常建议不要直接在命令行上指定密码,因为存在潜在的安全问题(密码可以出现在shell的历史文件和系统的进程表中):
$ ./program.sh --password 'secret' &
[1] 4152
$ cat /proc/4152/cmdline
/bin/sh./program.sh--passwordsecret
Run Code Online (Sandbox Code Playgroud)
但是,在搜索时,我没有看到针对Windows的强烈建议.
在为Windows编写程序和脚本时,我们是否应该提供另一种方法来输入除命令行选项的参数之外的密码,以避免无意中泄露密码?
这个问题的答案表明,专用的密码输入提示可以防止肩膀冲浪,从而提高安全性.有没有其他方法可以在命令字符串中利用可见密码来证明编写备用输入方法,无论是在shell的上下文中还是在Windows管理进程的方式中?
从批处理文件或PowerShell脚本启动程序时,安全隐患是否会发生变化,该脚本将密码作为参数传递给程序?
$password = # prompt for password
program.exe /password:$password
Run Code Online (Sandbox Code Playgroud)
编辑 - 我理解我们可以将这个问题误解为基于意见的问题,因为我提到"最佳实践"和"建议"来提供背景知识.但是,我寻求具体的证据来证明密码在命令参数中可能容易受到攻击,并且 - 如果这个假设是有效的 - 具体示例或描述安全备选方案的参考.
我似乎无法弄清楚如何在herestring中使用变量,以及稍后在管道命令中扩展变量.我尝试过单引号'和双"引号,以及转义`字符.
我试图将herestring用于Exchange组的列表(例如数组),以及应用于这些组的相应条件列表.这是一个简化的示例,它无法$Conditions正确使用变量(它不会扩展$_.customattribute2变量):
# List of groups and conditions (tab delimitered)
$records = @"
Group1 {$_.customattribute2 -Like '*Sales*'}
Group2 {$_.customattribute2 -Like '*Marketing*' -OR $_.customattribute2 -Eq 'CEO'}
"@
# Loop through each line in $records and find mailboxes that match $conditions
foreach ($record in $records -split "`n") {
($DGroup,$Conditions) = $record -split "`t"
$MailboxList = Get-Mailbox -ResultSize Unlimited
$MailboxList | where $Conditions
}
Run Code Online (Sandbox Code Playgroud) 为了测试,我创建了一个新的功能应用程序.我添加了两个函数,一个是http触发器,在调用时,将500条消息推送到队列.另一个是队列触发器来读取消息.队列触发器功能代码被设置为读取消息并从1到30秒随机休眠.这旨在模拟更长时间运行的任务.
我调用了http触发器来创建消息,然后看着que填满(消息由另一个触发器处理).我还将应用程序见解连接到此功能应用程序,但我没有看到超过1台服务器的规模.
Azure功能是否可以扩展到que中的#消息?
另外,我在Powershell中实现了这些功能.
我有一个powershell脚本,它根据给定目录中文件夹的名称生成一个ArrayList.因此,如果目录如下所示:
C:\目录\一
C:\目录\二
C:\目录\三
$ list是一个包含[One,Two,Three]的数组.该行如下:
[System.Collections.ArrayList]$list = (Get-ChildItem C:\Directory -dir).Name
Run Code Online (Sandbox Code Playgroud)
然后我可以遍历字符串数组并用它们做各种事情.但是,当目录中只有一个文件夹时,这将停止工作.它似乎不再是一个ArrayList而只是一个字符串.我收到以下错误:
Cannot convert the "Directory" value of type "System.String" to type "System.Collections.ArrayList"
Run Code Online (Sandbox Code Playgroud)
这可以做什么?我应该使用不同类型的数组吗?
如何让powershell"mkdir"命令完全像Linux的mkdir -p命令一样?
在Linux下,mkdir -p将创建嵌套目录,但前提是它们不存在.例如,假设您有一个/foo具有写权限的目录.mkdir -p /foo/bar/baz在现有的酒吧内创建酒吧和酒吧/foo.您再次运行相同的命令,您将不会收到错误,但不会创建任何内容.
我有一个包含@""@在其中的脚本:
$myHtml = @"
<html>
...
</html>
"@
Run Code Online (Sandbox Code Playgroud)
我想将所有这个脚本转换为字符串@""@转换为变量.
这是我试过的:
$string = @"
$myHtml = @"
<html>
...
</html>
"@
"@
Run Code Online (Sandbox Code Playgroud)
我可以通过读取字符串中的字节并将其转换为ASCII来执行解决方法:
# Read the entire file to an array of bytes.
$bytes = [System.IO.File]::ReadAllBytes("path_to_my_script")
# Convert to a text assuming ASCII encoding.
$text = [System.Text.Encoding]::ASCII.GetString($bytes)
Run Code Online (Sandbox Code Playgroud)
但我想学习如何用内部封装脚本@""@与外部@""@.
我想从一个范围生成一个随机数(比如1到3),但是从变量X中的那个范围特定数字中排除
所以我得到了这个代码
get-random -inputobject (1..4) | where {$_ -notin $X}
Run Code Online (Sandbox Code Playgroud)
这确实产生1到3之间的随机数,但是当生成数等于X中的数字时,它什么都不返回.
当它发生时我怎么能强迫它再次运行所以我总是得到一个数字,无论需要多少尝试?
powershell ×10
arguments ×1
arraylist ×1
filter ×1
formatting ×1
herestring ×1
parameters ×1
random ×1
security ×1
shell ×1
string ×1
structure ×1
variables ×1
windows ×1
windows-10 ×1