А теперь вопрос, правильно ли я понимаю, что при вводе например первого символа f из foobar фактически в powershell вводятся следующая последовательность: \b\b\b\bfhey1 ?
PS D:\> Write-Host 'tohost' > d:\111
tohost
PS D:\> Get-Content d:\111
PS D:\> Write-Output 'tooutput' > d:\111
PS D:\> Get-Content d:\111
tooutput
PS D:\>
Powershell -Noprofile -Command "Write-Host 'tohost'; Write-Output 'tooutput' " > D:\111
Powershell -Noprofile -Command "Get-Content d:\111"
import ctypes, sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
# Code of your program here
print("I'm admin")
input()
else:
# Re-run the program with admin rights
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
ctypes.windll.shell32.ShellExecuteW(None, "", "slmgr.vbs", "/ipk W269N-WFGWX-YVC9B-4J6C9-T83GX", None, 1)
foreach ($DatabaseName in $MyBase.Name) {
$BackupPath = $smoserver.Databases['msdb'].ExecuteWithResults("SELECT TOP 1 backupmediafamily.physical_device_name FROM backupset JOIN backupmediafamily ON backupset.media_set_id = backupmediafamily.media_set_id WHERE backupset.database_name = '$($DatabaseName)' ORDER BY backupset.backup_start_date DESC")
$BackupPath.Tables[0].physical_device_name
}
return $true
), то записать результат $result = Test-SQLConnection "Data Source=base;database=name;User ID=sa;Password=password;"
#так там будет true/false
New-Item -Path "C:\TbKassa\Bin" -Name "marker.txt" -ItemType "file" -Value $result -Force
#а так - 1/0
New-Item -Path "C:\TbKassa\Bin" -Name "marker.txt" -ItemType "file" -Value ([int]$result) -Force
if $u = ( $true) {
должно быть if ($u -eq $true) {
или просто if ($u) {
$no_remove = 'dir1', 'dir2', 'dir3'
$path = 'c:\temp'
Get-ChildItem $path | Where-Object { $_.Name -notin $no_remove } | Remove-Item -Force -Recurse -WhatIf
$_.Name -notin $no_remove -and 'Directory' -in $_.Attributes
-WhatIf
убрать > df
Filesystem Available Mounted on
NFS 8713914531840 /vmfs/volumes/Store
PS > New-HardDisk -VM MyVM -CapacityGB 100 -Datastore Store
> ls /vmfs/volumes/Store/MyVM/*flat.vmdk -la
107374182400 Dec 9 07:32 /vmfs/volumes/Store/MyVM/MyVM_1-flat.vmdk
> df
Filesystem Available Mounted on
NFS 8713914527744 /vmfs/volumes/Store
PS > 8713914531840 - 8713914527744
4096
Import-csv
вы никак не ускорите.$dataColl
- реальный кандидат на ускорение...
$dataColl = New-Object System.Collections.ArrayList
foreach ($Path in $Paths){
....
[void]$dataColl.Add($dataObject)
}
}
...
Measure-Command { $a = @(); 1..1000 | %{ $a += $_ } }
TotalMilliseconds : 40,3721
Measure-Command { $a = New-Object System.Collections.ArrayList; 1..1000 | %{ [void]$a.Add($_) } }
TotalMilliseconds : 18,5863
# А для 10000 уже
TotalMilliseconds : 2016,3737
vs
TotalMilliseconds : 57,6177
$oldfile = Get-FileHash .\old\*
$newfile = Get-FileHash .\new\*
Compare-Object $oldfile $newfile -Property Hash -PassThru |
Where-Object { $_.SideIndicator -eq '<=' } |
Foreach-Object { Copy-Item $_.Path -Destination $Destination }
$oldfile = Get-ChildItem .\old\* -Recurse | Get-FileHash
$newfile = Get-ChildItem .\new\* -Recurse | Get-FileHash
..
$row1 = @($buttonsubcheck, $buttonsubtrial)
$row2 = @($buttonsubback)
$buttonssub = ($row1, $row2)
..
$Computername = 'xxx'
Get-CimInstance Win32_Group -filter "LocalAccount='True' and SID='S-1-5-32-555'" -ComputerName $Computername |
Select-Object PSComputername,Name,@{Name="Members";Expression={
(Get-CimAssociatedInstance -InputObject $_ -ResultClassName Win32_UserAccount).Name
}}
$Computername = 'xxx'
Get-WMIObject Win32_Group -filter "LocalAccount='True'and SID='S-1-5-32-555'" -ComputerName $Computername|
Select-Object PSComputername,Name,@{Name="Members";Expression={
$_.GetRelated("Win32_UserAccount").Name
}}
function Get-LocalGroupMember {
param(
[Parameter(ValueFromPipeline=$false, Position=0)]
[string[]]$GroupName = 'Administrators',
[Parameter(ValueFromPipeline=$true)]
[string[]]$ComputerName = '.'
)
PROCESS {
foreach ($computer in $ComputerName) {
foreach ($group in $GroupName) {
$grp = [ADSI]"WinNT://$computer/$group,group"
Write-Verbose ('Group: ' + $grp.Path) # test for existance
$members = @($grp.psbase.Invoke("Members"))
if ($members) {
$members | Foreach-Object {
$name = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
$class = $_.GetType().InvokeMember("Class", 'GetProperty', $null, $_, $null)
$parent = $_.GetType().InvokeMember("Parent", 'GetProperty', $null, $_, $null) -replace 'WinNT://' -replace '.*/'
'' | Select-Object @{n='Class';e={$class}},@{n='Domain';e={$parent}},@{n='Name';e={$name}}
}
}
}
}
}
}
Get-LocalGroupMember -ComputerName MySuperServer -GroupName 'Пользователи удаленного рабочего стола', 'Remote Desktop Users'
$Paths = $Paths.FullName
foreach ( $Newpath in $Path)
?-Exclude *.xl*
тоже странно, проще проверить на xl* в коде, чем заставлять этим заниматься move-item. Может быть, вы ps заставляете по новой весь каталог обшаривать таким образом, а в нём 10000 файлов xls$referenceUser = Get-ADUser refuser -Property userParameters
Set-ADUser targetUser -Replace @{
userParameters = $referenceUser.userParameters
}