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
View Date_Manip.ps1
$certInfo = ls Cert:\LocalMachine\My | where { $_.Subject -eq $subject }
$expireDate = $certInfo.NotAfter
[int]$daysRemaining = New-TimeSpan -End $expireDate | Select-Object -ExpandProperty Days
$date = Get-Date
$1weekOut = $date.AddDays(7)
View Move-Files.ps1
#test path and then load location
$path = "V:\Movies\0_Collections\Sci-FI Top 50 movies Dvdrip\1-25"
$files = Get-ChildItem -Path $path -Recurse -Force `
-ErrorAction SilentlyContinue
foreach($file in $files){
Write-Host "-----------------------------" -ForegroundColor Gray
try{
Write-Host "Checking if " $file.BaseName "DIR exists"
$newDirPath = "$path\" + $file.BaseName
$check = Test-Path $newDirPath
View FizzBuzz.ps1
for ($i = 1; $i -le 100; $i++) {
if ($i % 15 -eq 0) {
"FizzBuzz"
} elseif ($i % 5 -eq 0) {
"Buzz"
} elseif ($i % 3 -eq 0) {
"Fizz"
} else {
$i
}