我想要一个小逻辑来比较两个数组的内容,并使用powershell获取其中不常见的值
例如,如果
$a1=@(1,2,3,4,5)
$b1=@(1,2,3,4,5,6)
Run Code Online (Sandbox Code Playgroud)
输出的$ c应该给出值" 6",这是两个数组之间不常见值的输出.
有人可以用同样的方式帮助我!谢谢!
有人可以帮助我使用下面的cmdlet的powershell v2版本.
$body =
"<wInput>
<uInputValues>
<uInputEntry value='$arg' key='stringArgument'/>
</uInputValues>
<eDateAndTime></eDateAndTime>
<comments></comments>
</wInput>"
$password = ConvertTo-SecureString $wpassword -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($wusername, $password)
$output = Invoke-WebRequest -Uri $URI1 -Credential $credential -Method Post -ContentType application/xml -Body $body
Run Code Online (Sandbox Code Playgroud) 我有一个脚本从vmm获取虚拟硬盘信息,我从服务器远程执行它,目前我无法获取本地主机中的pssession之外的变量值,请你帮我实现同样的目标.
PS C:\Windows\system32> enter-pssession iscvmm02
[iscvmm02]: PS C:\Users\su\Documents>Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager
[iscvmm02]: PS C:\Users\su\Documents>$hide= Get-VMMServer -ComputerName "iscvmm02.corp.avanade.org"
[iscvmm02]: PS C:\Users\su\Documents>$VM = Get-VM | where { $_.ComputerNameString -contains "idpsm02.corp.air.org" }
[iscvmm02]: PS C:\Users\su\Documents>$harddisk=$VM.VirtualHardDisks
[iscvmm02]: PS C:\Users\su\Documents>$h=$harddisk.length
[iscvmm02]: PS C:\Users\su\Documents>for($i=0;$i-lt$h;$i++){
New-Variable -Name "HardDiskType_$i" -value $harddisk[$i].vhdtype
New-Variable -Name "HardDiskLocation_$i" -value $harddisk[$i].Location
}
[iadpscvmm02]: PS C:\Users\su\Documents>Exit-PSSession
PS C:\Windows\system32>$harddisktype_0
PS C:\Windows\system32>$harddisklocation_0
Run Code Online (Sandbox Code Playgroud)
因为你可以看到变量输出给出null值,我无法保留值
有人可以帮我获取磁盘信息吗?我有 3 个磁盘,但我无法使用添加成员获取它们的信息。
我收到错误:
"Add-Member : Cannot add a member with the name "Disks" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter to overwrite it."
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
function Get-Inven {
param([string[]]$computername)
#Import-Module ActiveDirectory
foreach ($computer in $computername) {
$disks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $computer -Filter 'DriveType=3'
$os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer
#$comp = Get-ADComputer -Filter { cn=$computer }
$info = @{
'ComputerName'=$computer;
'OSVersion'=$os.caption;
'DnsHostName'=$comp.dnshostname
}
$obj …Run Code Online (Sandbox Code Playgroud) 大家好,有一种方法,我们可以显示进度条10分钟,统计百分比完成了10分钟的剩余时间?使用Write-Progress.
想得到一个帮助,想要一个正则表达式来消除"\"以及之前发生的事情,
Input should be "vmvalidate\administrator"
and the output should be just "administrator"
Run Code Online (Sandbox Code Playgroud) 可能重复:
比较两个数组并获得不常见的值
我想要一种逻辑来从数组中获取不常见的项目,例如:
$a=@(1,2,3,4,5,6)
$b=@(1,2,3,4,5,7,9,10)
Run Code Online (Sandbox Code Playgroud)
我希望输出$c为6,这是$b数组中缺少的元素,应仅将的内容赋予优先级$a。
谁能帮我这个忙吗?
谢谢!
我有一组正在运行的作业。
PS C:\vinith> Get-Job
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
2 scvmm2012-vin BackgroundJob Running True localhost Param...
4 scom2012sp1-vin BackgroundJob Running True localhost Param...
6 scorch2012-vin BackgroundJob Running True localhost Param...
8 scsm2012sp1-vin BackgroundJob Running True localhost Param...
10 spfoundation BackgroundJob Running True localhost Param...
Run Code Online (Sandbox Code Playgroud)
我想要一个进度条显示,直到作业正在运行,并且在 powershell 中作业状态变为“已完成”时应该说已完成
我想要取代之间的线条
<? and <Arguments>
Run Code Online (Sandbox Code Playgroud)
并且
</Arguments> and </Task>
Run Code Online (Sandbox Code Playgroud)
通过powershell和正则表达式
这是整个字符串
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Author>administrator</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<Enabled>true</Enabled>
<StartBoundary>2013-03-13T00:34:00</StartBoundary>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Settings>
<Enabled>true</Enabled>
<ExecutionTimeLimit>PT259200S</ExecutionTimeLimit>
<Hidden>false</Hidden>
<WakeToRun>false</WakeToRun>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<Priority>5</Priority>
<IdleSettings>
<Duration>PT600S</Duration>
<WaitTimeout>PT3600S</WaitTimeout>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
</Settings>
<Principals>
<Principal id="Author">
<RunLevel>HighestAvailable</RunLevel>
<UserId>SMETEST\Administrator</UserId>
<LogonType>InteractiveTokenOrPassword</LogonType>
</Principal>
</Principals>
<Actions Context="Author">
<Exec>
<Command>C:\Program Files\NetApp\SnapManager for Exchange\SMEJobLauncher.exe</Command>
<Arguments>new-backup -Server 'SME' -ManagementGroup 'Standard' -RetainBackups 8 -RetainUtmBackups 20 -Sto
rageGroup 'testingDB1' -UseMountPoint -MountPointDir 'C:\Program Files\MgrMountPoi
nt' -RemoteAdditionalCopyBackup $False</Arguments>
<WorkingDirectory>C:\Program Files\NetApp\SnapManager …Run Code Online (Sandbox Code Playgroud) 如何通过ADSI LDAP为用户获取这些属性,这些是的属性Get-ADUser,我需要ADSI的等效属性。
我的目标是查询整个域的所有用户并获取这些属性。
我尝试使用Get-ADUsercmdlet,并且在查询用户时超时。
Get-ADUser -Filter * -Properties enabled,PasswordNeverExpires,passwordexpired,Name,SamAccountName,mail,passwordla??stset -server sc |
where {$_.Enabled -eq "True"} |
where { $_.PasswordNeverExpires -eq $false } |
where { $_.passwordexpired -eq $false } |
Select Name,SamAccountName,mail,
@{l='PasswordExpires';e={$_.passwordlastset+(Get-ADDefa??ultDomainPasswordPolicy).MaxPasswordAge}},
@{l='DaystoExpire';e={(New-TimeSpan -Start (get-date) -end ($_.passwordlastset+(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge)).days}}
Run Code Online (Sandbox Code Playgroud)
上面的命令对几个用户有效,但是如果我查询大量用户,它将给出无效的枚举上下文。