Measure-VMReplication | gm -MemberType Properties
To Execute Script
powershell.exe –noexit &”c:\myscript.ps1”
gci C:\thomas | where {$_.Length -gt 1000} | Sort-Object -Property name
gci | Where-Object {$_.Name -like « s* »}
# Demande via consoles avec choix par défaut
$VMName = Read-Host « Enter the name of the Virtual Machine (Press [Enter] to choose TestThomas) »
if ($VMName -eq « »){$VMName= »TestThomas »}
if ($VMName -eq $NULL){$VMName= »TestThomas »}
# Afficher imprimante et lecteur réseau
$wshnetwork = New-Object -ComObject « wscript.network »
$wshnetwork.enumPrinterConnections()
$wshnetwork.EnumNetworkDrives()
$colprinters = $wshnetwork.EnumPrinterConnections()
# List Processes and Sort Reult
$args = « localhost », »loopback », »172.0.0.1″
foreach ($i in $args)
{
$strfile= »C:\thomas\ » + $i + « Processes.txt »
Write-Host « testing » $i « please wait… »;
Get-WmiObject -ComputerName $i -Class win32_process |
Select-Object name, processID, priority, threadcount, pagefaults, pagefileusage |
where {!$_.processID -eq 0} | Sort-Object -Property name |
ft | Out-File $strfile
}
# Account With no required Password
$args = »localhost »
ls $PSScriptroot\accounts.log
foreach ($i in $args)
{
Write-Host « Connecting to » $i « please wait… »;
Get-WmiObject -ComputerName $i -class win32_account -Filter « Domain=’$Env:ComputerName' » |
Select-Object name, disabled, SID, SIDType |
Sort-Object -Property name | Out-File -FilePath « $PSScriptroot\accounts.log »
}
# Retrive and sort service state
$args = « localhots », »loopback »
foreach ($i in $args)
{
write-host « testing » $i « … »
get-wmiobject -computer $args -class win32_service |
select-object -property name, state, startmode, startname |
sort-object -property startmode, state, name| ft *
}
# Get Hard Disk Details
$intDriveType = 3
$aryComputers = « loopback », « localhost »
set-variable -name intDriveType -value 3 -option constant
foreach ($strComputer in $aryComputers)
{« Hard drivers on : » + $strComputer
Get-WmiObject -Class win32_logicaldisk -ComputerName $strComputer |
where {$_.drivetype -eq $intDriveType}}
# Create multiple Folder
$intFolders = 10
$intPad
$i = 1
New-Variable -Name strPrefix -Value « testfolder » -option constant
do {
if ($i -lt 10)
{$intPad=0 New-Item -Path C:\thomas\mytest\ -name $strPrefix$intPad$i -ItemType directory}
else
{New-Item -Path C:\thomas\mytest\ -name $strPrefix$i -ItemType directory}
$i++}
until ($i -eq $intFolders+1)
########## Provider #########
gci -path c:\ | gm | where {$_.membertype -eq « property »}
gci c:\ | where {!$_.psicontainer}
gci -path c:\ | gm | where {$_.membertype -eq « property » -AND $_.typename -like « *file* »}
SL function:\
gci | where {$_.Definition -notlike « *set* »}
get-help *variable | where {$_.category -eq « cmdlet » } | fl name, category, synopsis, details, syntax, parameters, aliases
gci | sort {$_.name}
Get-psdrive | where{$_.name -like « c* »}
sl cert:\
gci -recurse >C:\thomas\a.txt;notepad.exe a.txt
gci |sort -Property name | where {$_.name -gt « t »}
Get-PSDrive
Get-Item -Path env:\
Get-Item -Path env:\ | gm
$ogjenv=get-item -Path env:\
$ogjenv.count
$ogjenv.get_count
$ogjenv.get_count()
$ogjenv.gettype()
#### Registry Provider
$strUserPath = « \software\microsoft\windows\currentversion\ » `
+ « explorer »
$strPath = « \volatile Environment »
$strName = « LOGONSERVER », « HOMEPATH », « APPDATA », « HOMEDRIVE »
Sl HKCU:\
Get-ItemProperty -Path $strUserPath
#### Creation share et verification
$VMPath = Read-Host « Enter the Hyper-V Host (Press [Enter] to choose C:\Hyper-V\$VMname ) »
if ($VMPath -eq « ») {$VMPath= »C:\Hyper-V\$VMname » }
if ($VMPath -eq $NULL){ $VMPath= »C:\Hyper-V\$VMname » }
If (!(Test-Path -path $VMPath))
{New-item -itemType directory -path $VMPath -force
New-Item -Path $LogPath -Value $LogName -ItemType Fil
Add-Content -Path $logpath -Value « Directory for VM created in $VMPath on $vmhost by SCVMM $vmmserver »
}
##### Test directory if exist else create
If (!(Test-Path -path $VMPath))
{
New-item -itemType directory -path $VMPath -force
}
### Recup @MAC
$cmd=&c:\windows\system32\ipconfig.exe /all
#$cmd[10]
$cmd|Foreach{
if($_ -match ‘([0-9a-f\-]{17})’)
{
$matches[1]
break
}
}
Parse the command-line and verify the 13 required parameters are present, if not display usage info if ($args -eq $null -or $args.Count -lt 13)
### Confirmation variable sinon exit
# Post back the settings to the user for confirmation write-host « ========================================================== » write-host « CONFIRM CONFIGURED SETTINGS » write-host « ========================================================== » write-host « HyperV Server to create VMs on: $VMHost » write-host « Base name for VMs: $VMBaseName » write-host « PVS boot network name (emulated nic): $NetworkName » write-host « Normal network name (synthetic nic): $NetworkName2 » write-host « Local path for HyperV server to store VMs: $VMPath » write-host « Number of VMs to create: $VMCount » write-host « Base number to start VM creation at: $StartCount » write-host « Minimum Memory to assign to VM: $MemMin MB » write-host « Maximum Memory to assign to VM: $MemMax MB » write-host « Number of CPUs for the VM: $NumCPUs » write-host « Dynamic Memory buffer: $MemBuffer% » write-host « Dynamic Memory weight value: $MemWeight » write-host « Profile Owner: $DomainUser » write-host « ========================================================== » $strConfirm = read-host « Please confirm these settings. Continue (YES)? » If ($strConfirm -ne « YES ») { write-host « You did not type out the word YES. Aborting! » exit 1 }
Cet article PowerShell : example est apparu en premier sur IT Consult.