Categories
Powershell

Adding User Principal Names in Active Directory via PowerShell for Federation

I wanted to update the UPN or User Principal Names in our AD, as we had a couple thousand users that had been in our AD for over 10 years, in the NT days. So they were created without UPN’s.

This will print out the list of users and output it to a file so you can review who will be changed. We did not want to change the admin users so I added a notlike clause.

get-aduser -Filter * -SearchBase ‘CN=Users,dc=vivithemage,dc=com’ | where {($_.userprincipalname -eq $null) -and ($_.name -notlike “*admin*”)} | format-table samaccountname,givenname,surname | Out-File c:\test\UPN-prechange2.txt

Reviewed the list, looked good, so I can now run this to make the blanket change, while manually specifying the domain name:

get-aduser -Filter * -SearchBase ‘CN=Users,dc=vivithemage,dc=com’ | where {($_.userprincipalname -eq $null) -and ($_.name -notlike “*admin*”)} | foreach { Set-ADUser $_ -UserPrincipalName (“{0}@{1}” -f $_.name,”vivithemage.com”)}

Lots of help from this article: http://blogs.technet.com/b/heyscriptingguy/archive/2013/08/13/add-user-principal-names-in-active-directory-via-powershell.aspx
and ss64.com

Categories
Operating Systems

power shell script unmounting system reserved

I need a powershell way to remove the system reserved drive letter, as there is no reason for our users to actually use that, and access it. In powershell drop this code in:

$target = (Get-Volume -FileSystemLabel “System Reserved”).DriveLetter+ “:”
$volume = Get-WmiObject Win32_Volume -Filter “DriveLetter=’$target'”

if ($null -ne $volume)
{
$volume.DriveLetter = $null
$volume.Put()
}

Save it, make sure it’s a ps1 file and execute, it will remove the Drive Letter, and unmount it.

Categories
Windows 7

Disable Windows Startup Repair as Default Option

I was having issues where my older raid card would not get recognized on the first boot, causing windows to reboot, then BSOD. So 50% of the time I would reboot and would be stuck on the repair screen, so I wanted to disable it. Apparently you can through the bcdedit!

bcdedit /set {default} recoveryenabled No

Categories
Operating Systems Powershell Uncategorized Windows 7

copy a file into all user directories via bat files for windows 7 or xp using a wildcard

I needed to copy one file into all of the user directories on computers. I ended up creating a for loop, print it, then use that list as a variable to throw in, worked great. This was one of the few things I could not find on google, so hopefully this hits a few keywords for people when they’re searching. IT IS POSSIBLE! This can be done in BAT, CMD, OR just dump it into a command pronpt changing your own directories/variables as needed.

REM this prints all users in C:\Users\ and then copies the EssUser.cfg file to the PartsDoc Dir
FOR /D %%G IN (c:\Users\*.*) DO xcopy /Y /H /R "E:\PartsDoc Updates\EssUser.cfg" "%%G\Documents\CLAAS\PartsDoc\"

Categories
Operating Systems server 2012

How to change license from server 2012 r2 eval with MAK key

I found out you can do this pretty simply. I wanted to change my 2012 R2 Standard Eval ISO to use my 2012 R2 Standard MAK key. I ran this in an elevated command prompt:

DISM /online /Set-Edition:ServerStandard /ProductKey:xxxxx-xxxxx-xxxxx-xxxxx-xxxxx /AcceptEula

replacing the x’s with your key, hit enter and it should work with a requested reboot right after it completes.

Categories
Windows 7

creating large, empty files in windows

I ran this in Windows 7, but using fsutil you have a LOT of options.

fsutil file createnew c:\testfile.txt 150000000

this created a 150mb empty file so I can use for testing. If you run fsutil you will see you have a lot more options:

8dot3name 8dot3name managment
behavior Control file system behavior
dirty Manage volume dirty bit
file File specific commands
fsinfo File system information
hardlink Hardlink management
objectid Object ID management
quota Quota management
repair Self healing management
reparsepoint Reparse point management
resource Transactional Resource Manager management
sparse Sparse file control
transaction Transaction management
usn USN management
volume Volume management

Categories
Windows 7

setting up putty to be used as a socks5 proxy over ssh

This was taken from: http://www.ocf.berkeley.edu/~xuanluo/sshproxywin.html

I am posting this for my own knowledge, just incase that site ever goes down.

Run PuTTY. It starts in the “Session” screen; fill in the settings for your SSH connection. The fields “Host Name” and “Port” are pretty self-explanatory. You can enter the username too by filling the “Host Name” field in the “user@host” format. Make sure “SSH” is selected in “Connection type:”.
Go to the “Connection” -> “SSH” -> “Tunnels” screen to configure our tunnel.
Under “Add new forwarded port:”, enter some big integer of your choice to enter for the “Source port” field. (The first thousand or so ports are sometimes reserved by the operating system; so pick something bigger.) Here I will use arbitrarily choose 1080 (the SOCKS port).
Leave the “Destination” field blank.
Select the “Dynamic” radio button.
Click the “Add” button. You should see a line in the text box that reads “D1080” (or whatever number you chose).
(For those interested, this is the “-D” option in OpenSSH.)
(Optional:) By default the a login session is opened in the terminal, which usually runs a “shell”, allowing you to run commands on the command line on the remote computer. If you absolutely do not wish to use this, you may be able to disable it via the following:
Go to the “Connection” -> “SSH” screen.
Check the “Don’t start a shell or command at all” box.
(For those interested, this is the “-N” option in OpenSSH.)
(Optional:) At this point, it is a good idea to create a saved session, so you do not have to go through this process every time. If you wish to do so, go back to the “Session” screen; enter a name for the session and click “Save”.
Now you can open the connection. Click the “Open” button at the bottom.
The session window will open. If this is your first time connecting, it will ask you to add the key; “yes” is recommended. Enter the password when prompted. (You may also set it up to authenticate using public key instead of password, but that is beyond the scope of this tutorial.)
The login session is now connected. As long as the session is open, you will now have a SOCKS proxy running on on the local computer (localhost) at port 1080 (or whatever port you chose).

Example: Mozilla Firefox browser
Go to “Tools” menu -> “Options”
Go to “Advanced” screen -> “Network” tab
In the “Connection” section, click the “Settings…” button
Select the “Manual proxy configuration” radio button
Make sure “Use this proxy server for all protocols” is unchecked
Make sure the “HTTP Proxy”, “SSL Proxy”, “FTP Proxy”, “Gopher Proxy” fields are cleared
For “SOCKS Host”, enter “127.0.0.1”, and for “Port” enter 1080 (or whatever port you chose)
Select the “SOCKS v5” radio button
Click OK. Click OK.
Preventing DNS leaks is supported in Firefox 1.5.0.2 and above. Do the following:
Go to the URL “about:config”
Find the setting “network.proxy.socks_remote_dns” and set it to “true”
Example: Internet Explorer browser
Go to “Tools” menu -> “Internet Options”
Go to “Connections” tab
Click the “LAN Settings” button
In the “Proxy server” section, make sure the “Use a proxy server for your LAN…” box is checked
Click the “Advanced” button
Make sure “Use the same proxy server for all protocols” is unchecked
Make sure the “HTTP”, “Secure”, “FTP” fields are cleared
For “Socks”, enter “127.0.0.1” as the address, and for “Port” enter 1080 (or whatever port you chose)
Click OK. Click OK. Click OK.
I don’t know of any built-in support for preventing DNS leaks

I take ZERO credit for this writeup, again, this is just for my knowledge if I need to reference it again.

Categories
Google chrome

using chrome with socks ssh proxy without any DNS leaks

For funsies, I wanted to try this.

I wanted to use my SOCKS proxy setup, which was very simple:

Then I wanted to use chrome to bypass all proxies that IE has setup AND make sure DNS leaks do not occur.

HOW TO SETUP SOCKS PROXY VIA SSH and PUTTY:
http://www.ocf.berkeley.edu/~xuanluo/sshproxywin.html

Once you have created your SSH socks connection add this flag to the end of your target for your chrome shortcut:

--proxy-server="socks5://127.0.0.1:6060" --host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE 127.0.0.1"

If your proxy is something other then 127.0.0.1, swap them out. Also swap your port out if that is not the one you used.

socksproxychrome

Once you close your chrome and reopen with the new shortcut you can go here to test:

whatismyip.com

This should show the destination IP and the next URL will show you that you are using your destination hosts DNS servers and NOT your local!

dnsleakstest.com

So cool.

Categories
Google chrome

How to remove the chrome bell in the notification tray icon

Well this is annoying! It used to be removed via: chrome://flags/ and then just disabling “Enable Rich Notifications Mac, Windows”, but now it is: “Notification Center behavior Mac”. You also have to leave the setting to DEFAULT, and not disabled. Then relaunch and it’s gone.

We shall see what it takes on the next go around to disable it. OY Google, please stop. Just make it the same option every time. This is current as of: Version 36.0.1985.143

Categories
linux Operating System Deployment

error when copying or overwriting the same directory name linux

my directory structure in linux – centos:

/home/html/prod/wordpress/update/
/home/html/prod/wordpress/

/wordpress/ is my wordpress install, and /update/ is my unziped download files and directories.

The errors I kept getting when trying to move or copy the entire directory while sitting in /home/html/prod/wordpress/update/ was:

mv: cannot move `wp-admin’ to a subdirectory of itself, `../wp-admin’
mv: cannot move `wp-content’ to a subdirectory of itself, `../wp-content’

cp: omitting directory `wp-admin’
cp: omitting directory `wp-content’

what I ended up doing was staying in the same directory ( /home/html/prod/wordpress/update ) and running:

cp -fR * ../

f = force
R = recursive

all went well, replaced the entire directory like I wanted and I just removed the /update directory and done.