yakk0.org a blog on technology in the real world

22Apr/100

Path variables in batch files

This is another post documenting something I used to fix a problem at work so I don’t forget about it. We were pushing out Firefox to all our systems yesterday via SCCM. It’s pushed out using a batch file to configure various things, and I noticed that although the batch file was being called from the dozen or so distribution points we have, the script was calling back to the main server. I’ve seen this before but never looked into a solution. I started searching for a variable or a way to get the path the script is run from and found this article posted in 2008 on myITforum.com. It is addressing the exact situation I was encountering.

8Mar/102

PowerShell: Add printers to DNS

I realized today that most of our printers at work did not have DNS entries. This isn’t a big problem for users because they’re on our print server and they get their printers through Group Policy. The Print server has each printer set up to the IPs. We just implemented a management system today, and it lists the printers by IP and because the DNS entries were “Unknown” for most of them, it wasn’t easy to determine what printer we were looking at.

I found several PowerShell examples on the web for interacting with Microsoft DNS servers, and took a bit from each to come up with this script. It takes the shared printer name and publishes that as the DNS name. This does cause a problem if you have spaces in a share name, but our environment doesn’t, so I didn’t program for that issue.

Here’s the script:

6May/090

One line administration – search and delete computer accounts

Here’s a quick one-line script I’ve been using to clean up some old computer accounts in active directory. It requires the dsquery and dsrm tools from the Server 2003 Admin Pack or the Remote Server Administration Toolkit.

@for /f %%a in ('DSQUERY COMPUTER -NAME *%1') do (dsrm %%a)

Save that in as a batch file and it’ll query Active Directory for computers including the argument passed.  Here’s an example with a naming structure where we have the last 4 digits of the MAC address in the name for uniqueness.

C:\>adrm.cmd 6736
C:\>(dsrm "CN=LABPC6736,OU=Labs,DC=yakk0,DC=org" )
Are you sure you wish to delete CN=LABPC6736,OU=Labs,DC=yakk0,DC=org (Y/N)? y
dsrm succeeded:CN=LABPC6736,OU=Labs,DC=yakk0,DC=org