Browsed by
Category: Scripts

Scripts I have written up, or mashed up from a variety of sources.

PHP to Scrape Instagram Content

PHP to Scrape Instagram Content

I have become fascinated with scraping content off of Instagram mainly for curiosity and helping my wife analyze her competitors pages in terms of hashtags, ranking, and image placement, times posted, etc. I was certain something had been written for this before that was free, but it seems like there are bits and pieces out there in python, php, and a variety of other languages. Not to mention many paid solutions. I stumbled into a piece on github: https://gist.github.com/cosmocatalano/4544576 and…

Read More Read More

Get GUID Remotely

Get GUID Remotely

Recently I had to pull the GUID of a server remotely at work, I didn’t quite know how to do this off the top of my head. I found a few websites that suggested the following commands: Get-WmiObject Win32_ComputerSystemProduct | Select-Object -ExpandProperty UUID Get-WmiObject Win32_ComputerSystemProduct -ComputerName HOSTNAME | Select-Object -ExpandProperty UUID Both work, but I wanted to make a small powershell script where it would prompt me for the hostname and get it. $hostname = Read-Host ‘What is the hostname’…

Read More Read More

Batch: Add New Registry Key Remotely

Batch: Add New Registry Key Remotely

As a systems administrator sometimes I find myself in a situation where I need to make a registry change across a few computers, or even a few hundred. I was googleing for a while this week trying to figure this out and saw some very complex solutions, but found a few sites to include TechNet that lead me into this much simpler solution: @echo off FOR /f %%F IN (feedme.txt) DO ( REG ADD \\%%F\HKLM\SYSTEM\example\example /v TestValue /t REG_DWORD /d…

Read More Read More

PowerShell: Extension Attributes Server 2012

PowerShell: Extension Attributes Server 2012

A few days ago I wrote up a small post on modifying extension attributes for computer objects in Active Directory. I recently set up a lab with Server 2012 and found that extensionattribute1 is now msDS-cloudExtensionAttribute1, and if you just drop in msDS-cloudExtensionAttribute1 without quotes it has issues… This gave me a small headache, after reading this link I found that simply putting quotes around it, fixed it. The following code should work better in a server 2012 enviornment. import-module activedirectory…

Read More Read More

PowerShell: Import-Module Active Directory Cmdlet

PowerShell: Import-Module Active Directory Cmdlet

For those looking to query or do something within Active Directory in a PowerShell script, one of the most common mishaps I see at work is people forgetting to import the model. Often times everything else is fine, no syntax errors, etc. A simple fix for that is: import-module activedirectory The error generally looks something like this: PS C:\Users\userone> New-ADComputer -Name test The term ‘New-ADComputer’ is not recognized as the name of a cmdlet, function, script file, or operable program….

Read More Read More

PowerShell: Create Computers from Names in a List

PowerShell: Create Computers from Names in a List

Sometimes I find the need to create 10-20 computers for my AD lab at home, to do this in PowerShell you can run the following command: Get-Content computers.txt | ForEach-Object { New-ADComputer -Name $_ } If you want to create the computer objects in an OU other than “Computers”, lets say you want to prestage a number of computer objects for a new department, you could do this: Get-Content computers.txt | ForEach-Object { New-ADComputer -Name $_ -Path “Specify Path”}

PowerShell: Modify Extension Attributes on a List of Hosts

PowerShell: Modify Extension Attributes on a List of Hosts

Some of you may find this useful, I ran into this problem where I needed to set the value of an extension attribute on a number of hosts from a list. The following script should take care of that. At the end, it will let you know that the host is finished, it will output an error if one occurs. import-module activedirectory $machines = Get-Content “C:\PATH TO LIST\feedme.txt” foreach($machinename in $machines) { Set-ADComputer $machinename -add @{extensionattribute10 = “VALUE IN THE…

Read More Read More

PowerShell: Get the hostname, mac, and IP remotely

PowerShell: Get the hostname, mac, and IP remotely

Normally I look around and find scripts to do things I need right away, sadly today, that was not the case! So, I looked at a few websites and was able to come up with this: $machines = Get-Content feedme.txt foreach($machinename in $machines) { get-wmiobject win32_networkadapterconfiguration -computer $machinename -filter “IPEnabled=’True'” | Select DNSHostname,MACAddress,IPAddress } Basically how it works is, you put your script and feedme.txt file in the same folder, the feedme.txt file has all of the machine names, then…

Read More Read More

PowerShell: Changing Account Expiration Dates

PowerShell: Changing Account Expiration Dates

Sometimes we need to change a large number of expiration dates and doing it by hand can be quite a task, here I have two examples on how to do this. Both required Quest Active Roles Management Shell for Active Directory. Example 1 – If all the account have an attribute such as the description that is the same, it can be done this way, but it MUST be the same and match exactly: Get-QADUser -ou “ou=users,dc=site,dc=local” -includedproperties description,AccountExpires,SamAccountName -sAMAccountName…

Read More Read More

PowerShell: Find User Accounts Expiring in 7 days

PowerShell: Find User Accounts Expiring in 7 days

This may help some of you; it looks for accounts within a certain OU and outputs their expiration date and email if their account expires in 7 days (no more, no less!). # Inspired by: http://gallery.technet.microsoft.com/scriptcenter/Email-Active-Directory-452a5640 # Modified for use by; Salomon Johns # Find users within a certain OU that have accounts expiring in 7 days (no more, no less) # Print out the results Get-QADUser -ou “ou=users,dc=test,dc=domain,dc=local” -includedproperties AccountExpires -sAMAccountName ‘*’ | ForEach-Object { $sevendays = (Get-Date).AddDays(7).ToString(‘yyyyMMdd’) $samaccountname…

Read More Read More