View DataCapture.ps1
$hostname = $env:COMPUTERNAME
hostname | Out-File C:\$hostname.txt -Append
ipconfig /all | Out-File C:\$hostname.txt -Append
Get-NetAdapter | Out-File C:\$hostname.txt -Append
Get-VMSwitch | Out-File C:\$hostname.txt -Append
Get-Cluster | Out-File C:\$hostname.txt -Append
Get-ClusterGroup | Out-File C:\$hostname.txt -Append
Get-ClusterResource | Out-File C:\$hostname.txt -Append
Get-ClusterNetwork | Out-File C:\$hostname.txt -Append
Get-Disk | Out-File C:\$hostname.txt -Append
View enable_HV_PS.ps1
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell -All
View cmd_commands.ps1
$command = 'C:\somepath\someexe.exe somearg'
iex $command
#full working example
$command = 'cmd.exe /c "C:\Program Files (x86)\Bginfo\BgInfo.exe" "C:\Program Files (x86)\Bginfo\config_2016.bgi\" /silent /accepteula /timer:0'
iex "& $command"
View Shares.ps1
$Shares=[WMICLASS]”WIN32_Share”
$Shares.Create("C:\folder\provisioning","Everyone",0)
View secureString.ps1
$password = Read-Host "Enter your password"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
View FileRemove.ps1
$path = 'C:\path\Test.txt'
if (Test-Path $path) {
Write-Host "$path detected, removing file before starting..."
try {
Remove-Item -Path $path -Force -Confirm:$false -ErrorAction Stop
}
catch {
Write-Host "Unable to remove $path"
}
View computerName.ps1
if ($txtComputerName.Text -notmatch '(?i)(?=.{5,15}$)^(([a-z\d]|[a-z\d][a-z\d\-]*[a-z\d])\.)*([a-z\d]|[a-z\d][a-z\d\-]*[a-z\d])$') {
$allGood = $false
[System.Windows.Forms.MessageBox]::Show("The computer name you specified was not valid.", "Computer Name not valid")
}
View suffixes.ps1
#set suffixes
$suffixes = "suffix1.int,suffix2.int,suffix3.int"
$command = @"
cmd.exe /C "wmic nicconfig call SetDNSSuffixSearchOrder ($domain,$suffixes)"
"@
Invoke-Expression -Command:$command -ErrorAction SilentlyContinue
#------------------------------------------------------------------------------
#reverse suffixes change
#Append Primary and connection specific DNS suffixes
#Append parent suffixes of the primary DNS suffix
View basics.ps1
#get the domain
$domain = $env:USERDNSDOMAIN
#Get Operating System Info
try {
$sOS = Get-WmiObject -class Win32_OperatingSystem
$Script:OS = $sOS.Caption
}
catch {
$Script:OS = "ERROR - Could not determine the OS version."
View progressBar.ps1
Write-Progress -Activity "Test" -PercentComplete 25
Start-Sleep(5)
Write-Progress -Activity "Test" -PercentComplete 50
Start-Sleep(5)
Write-Progress -Activity "Test" -PercentComplete 75
Start-Sleep(5)
Write-Progress -Activity "Test" -PercentComplete 100