Go Back   Hardware Canucks > SOFTWARE > O/S's, Drivers & General Software

    
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old August 7, 2013, 11:10 PM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default Anyone good with bat files?

is there anyone here good with bat files?

I'm making a bat file to handle some domain user removal, and save me some time so I don't have to manually log into a bunch of terminal server to removed the local roaming cache

but I thought, why stop there right?

this is just a snipet, basically it takes todays date, to append to teh folder name when it moves the roaming profile folder on the fileserver


set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4%

echo Moving user folder
move "D:\User Home Folders\%1" d:\todelete\%1_to_delete_%mydate%



my problem is....I don't want todays date, I want this day next month

so today being 08_08_2013, it should append 09_08_2013 to the folder name

anyone?

I would use powershell, but there's a couple command line utilities i'm using in the rest of the script that I could not find powershell equivalents for unfortunately, so bat file it is
Reply With Quote
  #2 (permalink)  
Old August 8, 2013, 10:01 AM
JD's Avatar
JD JD is offline
Moderator
F@H
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 6,904

My System Specs

Default

Why can't you use VBScript at the very least?
Reply With Quote
  #3 (permalink)  
Old August 8, 2013, 09:10 PM
grinder's Avatar
Allstar
F@H
 
Join Date: Mar 2007
Posts: 821

My System Specs

Default

bat files are so 1990's. powershell baby!

edit: for the proprietary BAT stuff I would use powershell to call the external bat files.
__________________
Phenom II 945 :: ASUS M4A78-E (780G) :: BFG 285GTX :: 4GB Mushkin DDR2 (5-4-4-12) :: Creative Xi-Fi :: Seagate 500 gig 7200.12 (better than WD BLACK!!!!!) :: Samsung 2493HM
Reply With Quote
  #4 (permalink)  
Old August 8, 2013, 09:29 PM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

JD: I don't do vb well at all, never been one for scripting. powershell I'm still learning. I don't care which way I do this, whether I do this in a bat, or powershell since I can call external commands if needed, I just need to figure it out

I can get it to append the date in either or, it's modifying it I'm having issues with, since this isn't my thing
Reply With Quote
  #5 (permalink)  
Old August 9, 2013, 06:37 AM
grinder's Avatar
Allstar
F@H
 
Join Date: Mar 2007
Posts: 821

My System Specs

Default

I don't know how valid of a date you want... technically a date with a month modifier could give you an invalid date.

i.e. if <today's date> is Jan 31st (01_01_2013) and you increment the month by 1 so it shows Feb 31st 2013 (02_31_2013) any date time function you perform to that folder will be invalid because it is an invalid date.

I would change your policy to 30 days instead of 1 hard month. In VB/powershell there are date-time functions that will let you dateadd 30 days instead of doing the month thing...

Code:
$a.GetDate
$b = $a.AddDays(30)
$c = $b.month.tostring() + "_" + $b.day + "_" + $b.year
$d = "C:\users\Rob\ThatGuy-" + $c
New-Item -ItemType Directory -path $d
will create the folder C:\Users\Rob\ThatGuy-9_8_2013
__________________
Phenom II 945 :: ASUS M4A78-E (780G) :: BFG 285GTX :: 4GB Mushkin DDR2 (5-4-4-12) :: Creative Xi-Fi :: Seagate 500 gig 7200.12 (better than WD BLACK!!!!!) :: Samsung 2493HM
Reply With Quote
  #6 (permalink)  
Old August 9, 2013, 02:33 PM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

technically the process documentation we have says 30 days, so if it's easier to script it to add 30 days, then it's perfectly fine by me. I'm not back into work until sunday night now, so I'll give it a go then. Until then, I've no need to think about it lol
Reply With Quote
  #7 (permalink)  
Old August 9, 2013, 02:55 PM
Shadowmeph's Avatar
Hall Of Fame
F@H
 
Join Date: Oct 2007
Posts: 3,372

My System Specs

Default

off topic as far as I am concerned it is allot faster and easier to make a simple bat file then it is to load up vb all you need is a notepad and a little knowledge. that being said I never that good at bat files never mind VB I really get confused with that
Reply With Quote
  #8 (permalink)  
Old August 9, 2013, 06:38 PM
JD's Avatar
JD JD is offline
Moderator
F@H
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 6,904

My System Specs

Default

VB can be written in Notepad too, Batch is only really good for simple tasks. Anything complex involving loops/if statements should be done in VB at least until Powershell becomes a de-facto standard.

Quick example:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")

CurrentDate = FormatDateTime(Date(), 2)
NewDate = DateAdd("m",1, CurrentDate)
SourceFolder = "c:\temp\folder1"
DestinationFolder = "c:\temp\delete_" & NewDate

fso.MoveFolder SourceFolder, DestinationFolder
That moves "c:\temp\folder1" to "c:\temp\delete_2013-09-09"

Last edited by JD; August 9, 2013 at 06:48 PM.
Reply With Quote
  #9 (permalink)  
Old August 11, 2013, 10:59 PM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

JD's example works. I'm just looking at my current batch file here and trying to figure out how to combine it

delprof2 is the only thing that really would need to run from the basic command shell though which could be called externally from powershell.

The main thing holding me back from turning this into a powershell script is I'm not entirely familiar with how to create a PS script to require an input parameter, such as the username you want removed, otherwise, this would be pretty simple. The other nice thing with powershell is I could easily add the exchange cmdlet functions to forward the email to another account, which would need a second input parameter, but hey



here's the existing batch file is anyone has any thoughts

Quote:
ECHO OFF
echo get todays date
set mydate=%date:~4,2%_%date:~7,2%_%date:~10,4%

echo how to modify the mydate to add 30 days and set to newdate var

cls

rem
rem Input validation
rem
if /i "%1"=="/?" goto usage
if /i "%1"=="" goto usage

echo ================================================== ======
echo. This will disable the following account : %1
echo.
echo. The password will be reset to : ********
echo.
echo. The profile will also be cleaned from the following
echo. servers:
echo.
echo. The Roaming profile folder will be moved to :
echo. d:\todelete\%1_to_delete_%mydate%
echo.
echo. TS1
echo. TS2
echo. TS3
echo. TS4
echo. TS6
echo. TS7
echo ================================================== ======
echo.
pause

echo Resetting password
net user %1 ******** /domain

echo Disabling domain account
net user %1 /active:no /domain

echo Moving user folder

move "D:\User Home Folders\%1" d:\todelete\%1_to_delete_%newdate%

echo cleaning profile from servers

echo change /q to /u to display output

DelProf2.exe /q /c:ts1 /id:"%1"
DelProf2.exe /q /c:ts2 /id:"%1"
DelProf2.exe /q /c:ts3 /id:"%1"
DelProf2.exe /q /c:ts4 /id:"%1"
DelProf2.exe /q /c:ts6 /id:"%1"
DelProf2.exe /q /c:ts7 /id:"%1"

echo Complete
pause
goto eof

:usage
echo.
echo. Example: offboard username
echo.

:eof

edit// looks like powershell is out. default policy on the domain in question to disable running scripts. not likely to change.

Last edited by stlouis1; August 11, 2013 at 11:15 PM.
Reply With Quote
  #10 (permalink)  
Old August 12, 2013, 05:25 AM
JD's Avatar
JD JD is offline
Moderator
F@H
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 6,904

My System Specs

Default

Quote:
Originally Posted by stlouis1 View Post
edit// looks like powershell is out. default policy on the domain in question to disable running scripts. not likely to change.
Exactly the reason why I cannot use Powershell at work either. It's rather unfortunate, but VBS is the defacto standard for now.

You can find so many VBScript examples online, I think you can figure it out
Reply With Quote
Reply


Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
which types of files are good on a SSD drive Shadowmeph Storage 5 October 13, 2012 06:45 PM
.rar files SGardiner O/S's, Drivers & General Software 17 July 7, 2011 04:05 AM
X-Files Blu Off Topic 15 May 26, 2011 05:57 PM
Batch files. encorp O/S's, Drivers & General Software 33 October 8, 2010 11:47 AM
Restoring files? Phobia O/S's, Drivers & General Software 6 January 19, 2009 12:14 PM