I needed to remove IIS logs older than a number of days due to the C drive filling up - I found some information on the net with regards forfiles (instead of using Powershell which was my first port of call but due to the server running Windows 2003).
The script removes files older than 3 days and outputs the errors to a log file (or should - nothing in my log file at present but I've had no errors to date!).
forfiles /p C:\WINDOWS\system32\LogFiles\W3SVC100\ /s /m *.* /d -3 /c "cmd /c del @path" >> C:\Temp\remove_file_log.txt
Thursday, 24 April 2014
Wednesday, 2 April 2014
SCCM 2007 - Remote Tools prompt for credentials
Issue where you are prompted for credentials after starting
Remote Tools and your account has the appropriate permissions.
Usually indicates that the SCCM client isn’t installed
correctly.
1 Uninstall client from the machine – choose the
appropriate method at the time. RDP, PSEXEC, etc.
a.
Go to Windows\ccmsetup folder.
b.
Run ‘ccmsetup /uninstall’
2 From the SCCM Console – Computer Management >
Collections > All Systems.
a.
Search for machine.
b.
Right-click on the machine name and choose ‘Install
Client’.
Check the log to see if the changes have taken
affect: C:\Windows\ccmsetup\ccmsetup.log
NOTE: To read the log properly you will need to use SMS
Trace.
Using PSEXEC for a remote command prompt:
C:\PSTools> psexec.exe \\<remote-machine-name>
cmd.exe
Links:
Wednesday, 26 March 2014
Powershell - Creating a scheduled task to run a script gathering application logs from a number of servers
Hmmm.... long title for such a small task.
As the title says - gathering the application log from a number of servers, running it as a scheduled task.
First of lets start with the script
## List of servers
$server = @('Server1','Server2','Server3');
## Get the application log of every server listed above
foreach ($computer in $server) {
Get-EventLog -ComputerName $server -LogName "Application" |
Export-csv -Path "C:\Data\Log_$((Get-Date).ToString('yyyy-MM-dd-hhmmss')).csv"}
I have found that the script does keep running and running and running......
(Note to self - fix!)
Which leads me onto the scheduled task.
As the title says - gathering the application log from a number of servers, running it as a scheduled task.
First of lets start with the script
## List of servers
$server = @('Server1','Server2','Server3');
## Get the application log of every server listed above
foreach ($computer in $server) {
Get-EventLog -ComputerName $server -LogName "Application" |
Export-csv -Path "C:\Data\Log_$((Get-Date).ToString('yyyy-MM-dd-hhmmss')).csv"}
I have found that the script does keep running and running and running......
(Note to self - fix!)
Which leads me onto the scheduled task.
The task is going to run on Windows 2008 R2 server.
Administrative Tools > Task Scheduler > Task Scheduler Library.
General
Created a Domain account purely for this scheduled task.
Run whether user is logged on or not.
Triggers
On a schedule
Daily
Set date/time
Set occurance
Stop task if runs longer than (I set mine to 4 hours)
Check the enabled box
Actions
Action - Start a Program
Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments: & 'C:\<path>\script-name.ps1'
Conditions
Left at default
Settings
Leave at default settings
History
Log of the task
The scheduled task should now run - the difficult part was working out what arguments should be added to the Actions.
Tuesday, 7 January 2014
Powershell - Query Group Membership in another Domain
This in one way that I know of to search another Domain by mounting it as a drive (I'm sure there are different ways of skinning a cat but this technique would work for a number of Domains - again I'm sure there are further options to be able to the same thing!!).
## Query Group Membership ##
Import-Module ActiveDirectory
## Mount AD as a drive ##
New-PSDrive -Name OtherDomain -PSProvider ActiveDirectory -Root 'DC=other,DC=domain,DC=co,DC=uk' -Server dc1.other.domain.co.uk -Credential DOMAIN\account
cd OtherDomain:
Get-ADGroup -Filter {Name -eq "ADGroup"} |
ForEach-Object{
$hash = @{GroupName = $_.Name ; UserID = '' ; Member = ''}
$_ | Get-ADGroupMember -ea 0 -recurs |
ForEach-Object{
$hash.Member = $_.Name
$hash.UserID = $_.SamAccountName
New-Object psObject -Property $hash
}
} | sort groupname, member | Export-CSV "C:\Data\ADGroup.csv" –NoTypeInformation
## Query Group Membership ##
Import-Module ActiveDirectory
## Mount AD as a drive ##
New-PSDrive -Name OtherDomain -PSProvider ActiveDirectory -Root 'DC=other,DC=domain,DC=co,DC=uk' -Server dc1.other.domain.co.uk -Credential DOMAIN\account
cd OtherDomain:
Get-ADGroup -Filter {Name -eq "ADGroup"} |
ForEach-Object{
$hash = @{GroupName = $_.Name ; UserID = '' ; Member = ''}
$_ | Get-ADGroupMember -ea 0 -recurs |
ForEach-Object{
$hash.Member = $_.Name
$hash.UserID = $_.SamAccountName
New-Object psObject -Property $hash
}
} | sort groupname, member | Export-CSV "C:\Data\ADGroup.csv" –NoTypeInformation
Powershell - Query Group Membership
A quick script to pull a list of users from a AD group:
## Query Group Membership ##
Import-Module ActiveDirectory
Get-ADGroup -Filter {Name -eq "ADGroup"} |
ForEach-Object{
$hash = @{GroupName = $_.Name ; UserID = '' ; Member = ''}
$_ | Get-ADGroupMember -ea 0 -recurs |
ForEach-Object{
$hash.Member = $_.Name
$hash.UserID = $_.SamAccountName
New-Object psObject -Property $hash
}
} | sort groupname, member | Export-CSV "C:\Data\ADGroup.csv" –NoTypeInformation
## Query Group Membership ##
Import-Module ActiveDirectory
Get-ADGroup -Filter {Name -eq "ADGroup"} |
ForEach-Object{
$hash = @{GroupName = $_.Name ; UserID = '' ; Member = ''}
$_ | Get-ADGroupMember -ea 0 -recurs |
ForEach-Object{
$hash.Member = $_.Name
$hash.UserID = $_.SamAccountName
New-Object psObject -Property $hash
}
} | sort groupname, member | Export-CSV "C:\Data\ADGroup.csv" –NoTypeInformation
Friday, 27 December 2013
Microsoft - SQL and anti-virus
Just read an interesting article on AV and SQL by Michael K. Campbell - short, but gets to the point. It has a link to a very useful Microsoft KB article on AV DLLs that cause SQL performance issues.
Thursday, 19 December 2013
Solaris - /tmp permissions
Had a bit of a problem when one of the guys decided to restore file to the /tmp directory instead of the original location.
The ownership changed on /tmp to the restored folders owner which had a knock on effect with some scripts.
To fix the problem the following commands were applied:
# chmod 1777 /tmp
# chown root:root /tmp
The ownership changed on /tmp to the restored folders owner which had a knock on effect with some scripts.
To fix the problem the following commands were applied:
# chmod 1777 /tmp
# chown root:root /tmp
Subscribe to:
Posts (Atom)