Labels
Wednesday, October 30, 2013
Introduction to PowerShell book in Dutch, PowerShell voor IT beheerders
Dit keer heb ik eens in het Nederlands een boek geschreven wat een inleiding geeft in PowerShell. doelgroep is IT beheerders die aan de slag willen met PowerShell en dit graag in het Nerderlands willen leren.
Link to the Book; Link naar het boek: http://sdrv.ms/1aop7Ea
Have fun with it and till next time.
Thursday, October 10, 2013
Get-ADUser and get their properties like all domain admins
$alldomainadmins=Get-ADGroupMember -Identity "Domain Admins"
When you have a variable of all AD domain admin objects you can do some interesting filtering. for instance you can get all domain admins with a certain common name:
$alldomainadmins|where {$_.distinguishedName -like "*internal*"}
another interesting application of this is the search for disabled accounts and logoncount like this:
Have fun, till next time
Tuesday, October 08, 2013
Microsoft Excel compatibility: “. cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only”
Case:
In the case of this error, the situation is as follows:Coming from Windows XP SP3 clients with Office 2003 (sp3) the end users got new PC’s with Windows 7 Prof SP1 and Office 2010 SP2. using these systems some users got back to me complaining they got the error “. cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only” this occurred when opening (old) .xls files (but i have also seen it with old .ppt and .doc files) on the network.
I should tell you the error we got was in Dutch, here it reads: “Kan geen toegang krijgen tot . Het bestand is mogelijk beschadigd of staat op een server die niet reageert. Het kan ook zijn dat het bestandeen alleen-lezenbestand is.
Solution:
So as mentioned the information box appears when Windows 7 wants to write this file to the offline files cache. the solution in domains is to disable Offline files on Windows 7 (default it is enabled in Windows 7, you explicitly have to turn Offline files feature off!). the solution is shown here and here.Analysis
The thing sticking out here is: the file in the error is designated as “.” this is an indication for a fault in name resolution. working on this error the primary analysis is: Opening a .xls file that resides on a network Excel opens the file in compatibility mode. We know this because the file is being opened in compatibility mode by excel and on display on the screen when the error is thrown. Hence the error is being caused by a process after opening the .xls file.Viewing the event log it warns me about Event ID: 300 Source: Microsoft Office 14 Alerts it tells me things like:
P1: application name that has occurred this error
P2: application version
P3: application time stamp
P4: Assembly/Module name
P5: Assembly/Module version
P6: Assembly/Module timestamp
P7: MethodDef
P8: IL offset
P9: exception name
In this case the application 100101 probably is explorer, version is the Excel version, the timestamp is really puzzling me though, it could be the event viewer is having trouble converting the timestamp code… I did some google-ing and found these threads: http://code.google.com/p/win-sshfs/issues/detail?id=42 http://social.technet.microsoft.com/Forums/office/en-US/56b360c5-1f80-4d8b-b7bc-43e421b7d3f2/excel-causes-error-on-open-cannot-be-accessed-the-file-may-be-corrupted-located-on-a-server?forum=excel they are both suggesting problems with accessing data, only one of them thinks it is a local computer issue.
Diving deeper
After seeing these threads i got the impression it would be something to do with the access of the network. i checked everything on name resolution, that was ok, secondly i checked all settings in Excel, they are all the same as the Citrix (server 2008 R2) environment on which it all works, no questions asked. they are all the same.So next up: troubleshooting steps.
After mapping the network drive directly to another drive letter i got it working without errors. what’s the difference? the mappings used in the problem are mapped from a DFS share! so not using the DFS mapping resolves the problem!! what’s the issue then? DFS maps network shares to a single ‘DFS tree’ mapping drives from this tree will result in windows calls to the DFS root, which, on its turn, will resolve the mapping to UNC named paths. So that’s probably the source of the erratic behaviour of Excel.
Reconstructing the cause together with the information drawn here makes me think Excel in compatibility mode will open a .xls file do some redrawing of some sort to make it accessible to the new Excel Open office file format (or something) and then write this information back to the original file. this last step does not seem to be successful…
Update: after further digging i came to the solution, it finally appeared to be an issue related with Offline files feature in Windows 7.
Workarounds
There are two general workarounds:- Open the file, cancel the error and convert it to the new (.xlsx) format.
- Map a new drive letter to the share from which the file is coming from and open it.
Some thoughts about this problem
First of all, Microsoft should give us more information about the way Excel works in compatibility mode (only from purely cosmetically point of view it should be solved) secondly converting all files to the new file format will give us a whole lot extra files (and overhead) aside from the storage problems it will probably raise.See you next time!
Thursday, September 19, 2013
AD Computer scanner with PowerShell for Windows 2003 and up with Gridview
As always; my days get all clogged with things i must do; for instance make an overview of all AD computer objects and sort out all obsolete items.
This can be done in many ways i just opted for the PowerShell way and using the Gridview. this thing is so powerfull out-of-the-box that the script itself remains small.
the output looks like this:
This grid will find: Name, Description, OperatingSystem, Servicepack,Lastlogontimestamp, Creation date, Logoncount and the time a bad password was put in.
The Gridview itself has some powerful filtering options. With the add criteria; filters items can be added. you just have to experiment with the filters to see what they can do.
This script does NOT use the ActiveDirectory PowerShell module. it just finds the AD domain root itself and connects to it with ADSI so this script can be run just about everywhere as long as it is a Windows Domain with PowerShell enabled on the scanning machine, this script, for example, is ideal to scan a Active Directory that is not Domain level 2008 or higher; it also runs good on older 2003 environments.
Please beware; in large environments this script can pull quite some LDAP traffic from a domain controller; it is not BITS enabled and does not use Qos
have fun with it
#####################################################
# Name: ADComputers Scanner
# Date: 19-9-2013
# Version: 1.0
# Creator: Bas Huygen
# Changetones:
#####################################################
#get ADSI information from root domain
$dc=[ADSI]""
$domain=$dc.distinguishedName
$domainexw="LDAP://"+$domain
$ADDomain=[ADSI]$domainexw
$ADSearch= New-Object System.DirectoryServices.DirectorySearcher
$ADSearch.SearchRoot=$ADDomain
$ADSearch.Filter= "(objectCategory=computer)"
$ADSearch.PropertiesToLoad.AddRange() 2>&1
#get all computers from the root domain
$results=$ADSearch.FindAll()
$array.Clear()
#Loop through all computers of the domain and gather information
foreach($res in $results){
$obj = New-Object PSObject
#$resdescr=$res.Properties.description
$obj | Add-Member NoteProperty Name ([string]$res.properties.name)
$obj | Add-Member NoteProperty Description ([string]$res.Properties.description)
$obj | Add-Member NoteProperty operatingsystem ([string]$res.Properties.operatingsystem)
$obj | Add-Member NoteProperty operatingsystemservicepack ([string]$res.Properties.operatingsystemservicepack)
$rawtime= [string]$res.Properties.lastlogontimestamp
$obj | Add-Member NoteProperty lastlogontimestamp([datetime]::FromFileTime($rawtime))
$obj | Add-Member NoteProperty Created ([string]$res.properties.whencreated)
#$pwlastraw=[string]$res.properties.pwdLastSet
#$obj | Add-Member NoteProperty PasswordLastSet ([datetime]::FromFileTime($pwlastraw))
$obj | Add-Member NoteProperty LogonCount ([string]$res.properties.logoncount)
$badpwdraw=[string]$res.properties.badpasswordtime
$obj | Add-Member NoteProperty badPasswordTime ([datetime]::FromFileTime($badpwdraw))
#Write-Output $obj
[array]$array += $obj
}
$Title = "Machine view of domain $domain"
$array| sort Name|Out-GridView -Title $Title
Friday, September 13, 2013
WakeUp! a small GUI to wake Windows Machines from a PowerShell script
Because i need it so much i took the script i published before on link and enhanced it with a little GUI. here is a screenshot:
It works like the script; the input is the MAC address from the line after MAC Address above and the script converts the MAC address to a unicast Wake on LAN packet. Next it will sent it through all connected Network adaptors connected.
On the Settings tab there are two lines: the DNS domain and the DHCP export file; used for retrieval of the cached MAC addresses.
It works like this: just type the machine name on the Computer Name line and hit Wake Machine the script will try to fetch the MAC address from the DHCP export. another way to use this app is to input the MAC address (with or without computer name) and hit Wake Machine this will also work.
Information about the DHCP Export can be found here (again) .
The two lines on the settings tab are reset to default every time the scripts starts. to change these lines to your own default, edit lines: 289 and 320 from the script.
the script can be downloaded here: http://sdrv.ms/ZyH49Q
please beware, it is not signed, smart screen will warn you about that.
‘Good morning to you machines”
Wednesday, September 11, 2013
How to Setup SQL Server for Config Manager 2012 SP1 (SCCM)
Because i have had quite some trouble setting up a SQL Server for Config Manager 2012 on a separate server i decided i should write this down and share it to other people having similar problems:
So for Config Manager 2012 the requirements for a database are the following (excerpt from http://technet.microsoft.com/en-us/library/jj628198.aspx)
|
SQL server installation
To install an SQL server just follow the standard installation for a server and DO NOT SELECT EXPRESS version; SCCM Central site does not support EXPRESS versions of SQL server.
During installation of SQL the only thing to remember is: select a domain account for the SQL Server service:
I am a typical IT admin so i am lazy when it comes to configuration in a test lab, so i used the domain administrator account for this test version; please do not do this in a production environment; be a good boy/girl and create a service account for this!
After the installation of SQL server has finished you have to configure the server for three things:
- Firewall
- SQL configuration
- Local administrators of the SQL server
The first one is quite simple: fire up the Firewall application and add a port rule for TCP 1433 and TCP 4022 to allow minimally the Domain profile.
SQL installation itself does also add the SQLServer x64 to the firewall, this can stay because it does not do any harm.
Next the SQL configuration: this one did cost me most of my time because i did not notice the message:
The instance name that you use for the site database must be configured with a static TCP port. Dynamic ports are not supported
This is really important: so i repeat : DO NOT USE DYNAMIC TCP PORTS ON SQL SERVER FOR THE SITE DATABASE OF SCCM 2012
The configuration of the sql service look like this:
remember: the TCP Dynamic ports must be blank on all IP’s you use. also the TCP ports all must have 1433 when you use this (default) SQL server port for SQL transactions.
The last configuration is the addition of the SCCM server computer account to the local administrators group of the SQL server because i you don’t you receive an error like this in the prerequisites check of SCCM 2012 SP1
to enable this do the following:
Open the local user and groups MMC on the SQL server and open the group administrators: add the COMPUTER account of the SQL server to this group, like this:
after this, the prerequisites check should be fine and the SQL portion of the installation is complete.
See you next time!
Monday, September 09, 2013
Handy Computer scanner
For this i have bundled a few scripts i created and used before and wrapped them into one GUI to scan a machine and get the information presented in a GUI.
Here are some screenshots:
The scanner works real easy: just input the computer name and hit Get Computer Information. or just hit <Enter>
This version exports a csv to a path specified behind the Export to CSV checkbox. by default the checkbox is checked.
to change this behaviour goto line 1143 and edit the line to:
$cbExport.Checked = $False
To change the location to which the CSV file is written, edit the line: 1137
$tbCSVExport.Text = "D:\Software\_ScannerOutput\%Computername%.csv"
For the scanner to work the target computer must be WMI- and remote registry enabled. Links: http://kb.gfi.com/articles/Skynet_Article/how-to-enable-remote-registry-through-group-policy
http://kb.gfi.com/articles/Skynet_Article/how-to-enable-remote-registry-through-group-policy
The script can be downloaded here: http://sdrv.ms/166HegJ