PowerShell

Краткий справочник по PowerShell - powershell_reference.doc

Как отправить e-mail с помощью PowerShell.

$MessageParameters = @{
Subject = "New Mail"
Body = "Test Mail"
From = "smtpFrom"
To = "smtpTo"
SmtpServer = "smtpServer"
}
Send-MailMessage @MessageParameters -BodyAsHtml -Encoding utf8

Create VM on the Hyper-V 2012 host

# Create VM

New-VM -Name "NewVM" -MemoryStartupBytes 2GB -NewVHDPath NewVM.vhdx -BootDevice CD -NewVHDSizeBytes 40GB -SwitchName Internal

# Check the controller

Get-VM -Name NewVM | Get-VMHardDiskDrive

# Check the type of HDD created

Get-VM -Name NewVM | Get-VMHardDiskDrive | Get-VHD

# Configure the BIOS

Get-VM -Name NewVM | Set-VMBios -EnableNumLock

# Increase the number of processors

Get-VM -Name NewVM | Set-VM -ProcessorCount 2

# Configure Dynamic memory

Get-VM -Name NewVM | Set-VMMemory -DynamicMemoryEnabled:$true -MaximumBytes 4096MB -MinimumBytes 786MB

# Load ISO

Set-VMDvdDrive -Path D:\Downloads\Server2012.ISO -VMName NewVM

# Configure VM starup/stop options

Get-VM -VMName NewVM | set-VM -AutomaticStartAction Nothing -AutomaticStopAction Shutdown

# Start the VM

Start-VM -Name NewVM

iSCSI Target Powershell

 Function New-Target ($Name, $Initiators, $Size, $Path) {
New-IscsiServerTarget -TargetName "$Name" -InitiatorIds $Initiators
New-IscsiVirtualDisk -DevicePath $Path -Size $Size
Add-IscsiVirtualDiskTargetMapping -TargetName "$Name" -DevicePath $Path
}

Выгрузить пользователей по списку из Active Directory (Поиск пользователя по имени)

$data = Get-Content C:\DATA\PowerShellCMD\ActiveDirectory\List.txt
write-host $data.count total lines read from file
$(foreach ($line in $data) {
Get-ADUser -Filter {Name -eq $line} -Properties Name,SAMAccountName,UserPrincipalName | Select Name,SAMAccountName,UserPrincipalName }) | `
Export-CSV -encoding "unicode" C:\DATA\PowerShellCMD\ActiveDirectory\ExportUserAD.csv

 

Import-csv C:\DATA\PowerShellCMD\ActiveDirectory\ImportUserList1.csv | ForEach {
$UserName = $_.Name
Get-ADUser -Filter {Name -eq $UserName} -Properties Name,SAMAccountName,UserPrincipalName | Select Name,SAMAccountName,UserPrincipalName }

 

Permanent link to this article: http://www.blogss.ru/powershell

Добавить комментарий

Your email address will not be published.