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

    
Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old August 12, 2013, 09:40 AM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

oh yeah, i've been stashing my own examples in a script folder i've been keeping. I'll handle it for sure.

it really bothers me now that powershell is disabled. I work in a place where our core business is remote monitoring and management, you'd think powershell would be available....though I also would have expected more core servers, because lets face it, other than terminal servers, real servers don't need GUI's
Reply With Quote
  #12 (permalink)  
Old August 12, 2013, 10:20 AM
Shadowmeph's Avatar
Hall Of Fame
F@H
 
Join Date: Oct 2007
Posts: 3,374

My System Specs

Default

Wished there was a free place to learn VB well that and also I had the patience to learn it
Reply With Quote
  #13 (permalink)  
Old August 12, 2013, 07:56 PM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

heh, my patience for scripting is limited too. took me forever to fix the error I was getting with my own login script at home that maps all my network drives
Reply With Quote
  #14 (permalink)  
Old August 13, 2013, 01:08 AM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

ok, well, i've got some powershell ebooks, figured I couldn't go wrong starting off with powershell for dummies LOL

so now, with a handful of books for reference and google, i'm looking over my existing batch file to see about converting it over to PS. Mainly out of curiosity at this point since for the moment I can't use powershell anyway.

But I may be able to convince the MSP to let me/us enable powershell, I like dealing with this particular MSP, he knows his stuff, follows standards, well organized, and if automating something like this means there's less room for dumb helpdesk agents to screw up, he'll be all for it

Last edited by stlouis1; August 13, 2013 at 02:21 AM.
Reply With Quote
  #15 (permalink)  
Old August 13, 2013, 03:08 AM
Top Prospect
 
Join Date: Apr 2013
Location: Ottawa
Posts: 220

My System Specs

Default

OK, I've converted it to Powershell which really took nothing. NOW, I only have one issue, it works, but there's got to be a better to do the last part, rather than repeating the same line with a different number, no doubt there's a way to have it repeat on it's own with a higher number

but here's what it is for now. it gets me one step closer to what I want as compared to my batch file, now I don't have to manually rename the folder to correct the date. next step, exchange mail forwarding

Quote:
# setting delprof2 path.
$delprof = "C:\delprof2\delprof2.exe"

# define the desired new password
$password = "p@ssw0rd"

# prompt for user name input
$user = Read-Host "Enter username"

# disable users AD account
Disable-ADAccount $user

# change the users AD password to the previously defined password
Set-ADAccountPassword -Identity $user -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $password -Force)

# get the current date
$Date = Get-Date

# modify the date to add 30 days
$day = $Date.AddDays(30)
$append = $day.month.tostring() + "_" + $day.day + "_" + $day.year

# define users profile folder path
$curpath = "D:\User Home Folders\$user"

# define the path where the users profile folder will be moved
$newpath = "d:\ToDelete\$user" + "_ToDelete_" + $append

# move the users folder and rename it to append the modified date
Move-Item -Path $curpath -Destination $newpath

# Running delprof on terminal servers
&$delprof /u /c:ts1 /id:$user
&$delprof /u /c:ts2 /id:$user
&$delprof /u /c:ts3 /id:$user
&$delprof /u /c:ts4 /id:$user
&$delprof /u /c:ts6 /id:$user
&$delprof /u /c:ts7 /id:$user

Last edited by stlouis1; August 13, 2013 at 04:05 AM.
Reply With Quote
  #16 (permalink)  
Old August 13, 2013, 05:33 AM
JD's Avatar
JD JD is offline
Moderator
F@H
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 6,905

My System Specs

Default

As "pseudo-code", I think it would be:

$num = 1
Do until num=7
$tsname = "ts" + num
&$delprof /u /c:$tsname /id:$user
$num = $num + 1
End
Reply With Quote
  #17 (permalink)  
Old August 13, 2013, 08:18 AM
"Quote This..."
F@H
 
Join Date: Nov 2007
Location: Hell
Posts: 3,832
Default

Quote:
Originally Posted by JD View Post
As "pseudo-code", I think it would be:

$num = 1
Do until num=7
$tsname = "ts" + num
&$delprof /u /c:$tsname /id:$user
$num = $num + 1
EndDo
Fixt.
Reply With Quote
  #18 (permalink)  
Old August 13, 2013, 08:42 AM
Shadowmeph's Avatar
Hall Of Fame
F@H
 
Join Date: Oct 2007
Posts: 3,374

My System Specs

Default

Quote:
Originally Posted by grinder View Post
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
isn't there a way to actually use the Calendar month instead of 30days. like you show here ( Jan 31st (01_01_2013) and you increment the month by 1 so it shows Feb 31st 2013) it will still be wrong becasue in feb it has 28days and in other monthers it has 30 or 31 days so over a period of a few months it will be way off.
or does the date actually matter in this script?
Reply With Quote
  #19 (permalink)  
Old August 13, 2013, 06:08 PM
JD's Avatar
JD JD is offline
Moderator
F@H
 
Join Date: Jul 2007
Location: Toronto, ON
Posts: 6,905

My System Specs

Default

Quote:
Originally Posted by Shadowmeph View Post
isn't there a way to actually use the Calendar month instead of 30days. like you show here ( Jan 31st (01_01_2013) and you increment the month by 1 so it shows Feb 31st 2013) it will still be wrong becasue in feb it has 28days and in other monthers it has 30 or 31 days so over a period of a few months it will be way off.
or does the date actually matter in this script?
The VBS code I posted goes by calendar date/month, so it abides to leap years and such. I'd assume a similar function exists in PowerShell.
Reply With Quote
  #20 (permalink)  
Old August 13, 2013, 06:42 PM
grinder's Avatar
Allstar
F@H
 
Join Date: Mar 2007
Posts: 821

My System Specs

Default

sorry i don't understand the question.

With Date Add you are doing math against a "date variable", not an "Integer variable". Adding 30 to one will have a different effect on the other with respect to months.
__________________
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
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