Skip to content

Instantly share code, notes, and snippets.

@ddhahn
ddhahn / FindGatewayServers.ps1
Created February 1, 2013 16:45
Looks for a service on a remote computer and logs the server name to a file if it's found
$servers = get-content C:\temp\potential_gateways.txt
foreach($server in $servers){
Get-Service -ComputerName "$server" -Name "Bentley SELECT Server Gateway" -ErrorVariable serviceerr
if ($serviceerr.count -eq 0) {
Write-Host "$server appears to be a gateway server"
Out-File -InputObject $server -FilePath c:\temp\selectservers.txt -Append -Encoding ASCII
}
else{
Write-Host "$server is not a gateway server"
}
@ddhahn
ddhahn / RestoreGPOsfromFile.ps1
Created February 1, 2013 16:43
Restore GPOs from file
#create new GPO's named in the file, then import the right gpo into that policy
$gpos = get-content("c:\temp\gpos.txt")
foreach ($gpo in $gpos) {
import-gpo -backupgponame "$gpo" -targetname "restored - $gpo" -path "c:\temp\backups"
}
@ddhahn
ddhahn / BackupGPOsfromFile.ps1
Created February 1, 2013 16:42
Backup GPO's that are named in a file
#Backup GPO's who's names are in a file
import-module grouppolicy
$gpofile = "C:\temp\gpos.txt"
$gpos = get-content($gpofile)
foreach($gpo in $gpos) {
$gpobackup = backup-gpo $gpo -path "c:\temp\gpobackup"
@ddhahn
ddhahn / Makebootstrapini.ps1
Created February 1, 2013 16:41
Uses a CSV of locations and gateways to help generate a bootstrap.ini file
##generate bootstrap.ini settings
$csv = Import-Csv -Path c:\temp\import.csv
del c:\temp\defaultgateway-out.txt
del c:\temp\defaultgateway-out1.txt
for ($i=0;$i -le $csv.count;$i++) {
##output assignments for [defaultgateway] string
$outstring = $csv[$i]."Default Gateway for Workstations (used to target deployroot)" + "=" + $csv[$i]."office name"
@ddhahn
ddhahn / PingMachines.ps1
Created February 1, 2013 16:34
Ping a list of machines and write the results to two files. machines that are alive and machines that don't respond
$machines = get-content("c:\temp\machines.txt")
foreach ($machine in $machines) {
#check for DNS resolution
$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$machine'" | Select-Object StatusCode
if ($PingStatus.StatusCode -ne 0) {
@ddhahn
ddhahn / LDMSMachineFilter.ps1
Created February 1, 2013 16:32
Takes a list of computers and creates a filter that can be pasted into LDMS query.
$filter = "<filter> "
$computername_string = "`"Computer`".`"Computer Name`" = "
$machines = Get-Content "c:\temp\del_machines.txt"
$filter_string = $filter
foreach ($machine in $machines) {
if ($machine -ne "ServerName") {
@ddhahn
ddhahn / ipfilter.ps1
Created February 1, 2013 16:30
Filters a list of IP addresses
del "c:\temp\vpn_machines.txt"
$machines = gc "c:\temp\hosts" |% {$_.split("`t")[0]}
foreach ($machine in $machines) {
if ($machine.startswith('10.54')) {
@ddhahn
ddhahn / AddMachinesToGroup.ps1
Created February 1, 2013 16:28
Add a list of AD computers to a group
#needs to be adapted to eliminate the need for Quest AD add in and use the built-in AD stuff in
#POSH 2.0
$machines = Get-Content "c:\temp\machines.txt"
foreach ($machine in $machines) {
Add-QADGroupMember "GroupName" -Member "contoso\$machine$"
@ddhahn
ddhahn / IsItInAD.ps1
Last active December 12, 2015 01:38
Is it in AD? Takes a list of machine names from a file and sees if there is an computer object by that name in AD.. If not, writes the name of the computer to a file
$machines = Get-Content "c:\temp\machines.txt"
del c:\temp\not-in-ad.txt
foreach ($machine in $machines) {
#query AD to see if this machine exists. If not, write to a file
#uses the quest AD cmdlets..Probably need to change to built in AD cmdlets in POSH 2.0
$this = Get-QADComputer -Identity "contoso\$machine$" -ErrorVariable $Error_get_computer
@ddhahn
ddhahn / RemoveADUserFromGroup.ps1
Last active December 12, 2015 01:38
Remove AD user from AD groups stored in a file
#read a list of CN's of groups from a file and remove the specified user from
#that group
#uses the quest AD cmdlets.. Probable need to change to built in AD stuff.
$groups = Get-Content "c:\temp\groups_to_remove.txt"
foreach ($group in $groups)
{
Write-Host $group