Posts

Showing posts from 2014

Powershell Get MAC Address

Below is a powershell function used to get a list of MAC addresses on a computer using WMI: function Get-MACAddress { <#     .SYNOPSIS       Displays the list of MAC addresses on a computer.     .DESCRIPTION      This function lists all MAC addresses on local computer or a remote one using WMI.     .EXAMPLE      Get-MACAddress      This command returns a list of all MAC addresses on the local computer.     .EXAMPLE      Get-MACAddress -ComputerName client01 -Credential $cred      This command returns a list of all MAC addresses on computer 'client01' using the $cred credentials. #>     Param     (         [string]$ComputerName = ".",         [system.management.automation.psCredential]$Credential     )     if($Credential)     {         Get-WMIObject -Class win32_networkadapterconfiguration -ComputerName $ComputerName -Credential $Credential | Where-Object {$_.macaddress.length -gt 0} | Select-Object -Property Description, MACAddress | For

NetScaler IP Address Conflict

I opened up my Citrix Command Center today and I had hundreds of messages regarding IP conflict -on a NetScaler. In order to resolve this I had to get the MAC address of the machine that creates the conflict, and what better way from the command line. I fired up Putty and connected to the NetScaler instance facing the conflict. I switched to the linux shell using the shell command and then I run nsconmsg -K /var/nslog/newnslog -d consmsg to get the relevant messages. Be vary careful with the above command and always use capital K. An other way to get this kind of messages it using the Diagnostics page within the GUI. Another thing to note is that you should check the HA status if you have two instances and you get the conflict about a VIP. If the IP with the conflict is the NSIP then you should check the network cables or the virtual adapters and the networks you have the connected to.

WAN Emulation using WANEm

Let's say that we have to test some application, that can be a web application, a TCP/IP application or any other kind of connection, in an environment that simulates the WAN. First of all we have to design the network environment. Most times, I use a Hyper-V environment to do setup the machines and networks needed for the test. Lets say that we've already setup a server and a client as virtual machines with names SERVERVM and CLIENTVM respectively. Each has one virtual network adapter. Now we need to create two new virtual networks, let's name them SERVERNET and CLIENTNET. We connect the client's adapter to the CLIENTNET and server's adapter to SERVERNET. The next thing we have to do is create the WAN emulation virtual machine. I prefer to user the WANEm  emulator. So grab a copy of the ISO and create a new VM. If you are using Hyper-V, remove the Virtual Network Adapter from the VM and add two new Legacy Network Adapters. Connect the adapters

Active Directory NTP

Due to the fact that most Windows authentication operations rely heavily on Kerberos and the significant part that time plays, you should always configure time sources for your active directory forests and domains. In active directory all computers update their time settings from the domains controllers and they in turn update using the domain controller holding the PDC Emulation FSMO role. So you should always verify that your PDC is able to access the extrnal time source. The command I use to check this is  w32tm /stripchart /computer:time.nist.gov.  If you do not get any errors from this command then you're probably set. Another way to check this is to check your firewall's logs after configuring the time settings on PDC. Since a different department may be responsible for the networking, the first way may be the best way to go. One last thing I use do is to run the command on some clients that may have firewalls between them and the domain controllers or to verify NT

Skydrive Crashing

For quite some time now, the Skydrive application on my computer was crushing. I was getting errors in the Application log stating: "Faulting application name: skydrive.exe, version: 6.3.9600.17278". I could also see a lot of Skydrive icons in the tray but they disappeared when I hovered the mouse over them. After some online searched I runned across a post suggesting to use the Onedrive Troubleshooter (you can get it from  here ) to search for problems and reset Onedrive if needed. I ended up resetting and everything is working fine now after an initial sync. There are also some command line switches you can use on skydrive.exe to stop and reset but I haven't used them.

How to get Microsoft Windows system info using Powershell

There are many times that I have to get the system information like Windows Edition, Version, Architecture etc, in order to create support case or post to a forum. Since I use Powershell for almost everything, I have a script with the following commands to get that info: Windows Edition (Get-WmiObject -class Win32_OperatingSystem).Caption Windows Version (Get-WmiObject -class Win32_OperatingSystem).Version Processor Info (Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture I'm using WMI cause I want to be able to get the above info from remote systems as well. If you want more information about a system take a look at the Win32_OperatingSystem class  here . If you want to act based on the above info, it may be better to use some environmental variables and get the exact values.

Windows Username to SID mapping

I needed to map the sids of some users to their usernames the other day so I though that I should be able to use WMI to do it. Indeed, you can use the command wmic useraccount get name,sid  that will output a list of usernames and their sids. If you try to run this on Powershell you'll get an error message about invalid GET expression, that is because of the comma. You can use the Start-Process cmdlet and start the command with the necessary arguments.

Citrix Access Gateway 4.5 Certificate Renew

I had a request recently to update the certificates on two Citrix Access Gateways v4.5. I had the certificates for the URLs in .pfx format and the Root CA certificates also cause these had also expired. The Citrix Access Gateway Administration Tool was installed at one of the Web Interface servers so the only thing I had to do was to convert the certificates and install them. I installed the OpenSSL libraries to a Windows 7 vm, copied the certificates over and converted them with the command:  openssl pkcs12 -in c:\certs\ yourcert .pfx -out c:\certs\cag.pem –nodes I also converted the Root CA certificates to Base64 format. I logged into the devices using the Administration tool, switched to the "Administration" tab and updated the Root CA certificate and then the certificate for the URL. These certificates had a different private key from the previous ones so I selected the option to upload the private key too. After that, I restarted the devices  and eve

Powershell Error Handling

Writing powershell scripts often; If yes, I believe that you have to be checking for errors for every command. A quick way that I use if to check the variable $error. I get the value $error.Count before a command and then compare that value to the value after the command. If it's increased, something went wrong. You may also want to get the error that occurred. Good news, you can use the variable $error[0]. For any other stuff, take a look at the other members and properties of the $error variable..

Java Update Group Policy

For quite some time now I have users that complain about the Java update notifications and want me to log in and update with my credentials. Since there is not need to have the latest Java version available as soon as possible, I decided to create a group policy object and disable the update notifications and process for all client computers. I will of course continue to update Java on those computers manually. There are two ways to do this, either create a ADM file with the settings or just add the changes as registry settings. I decided to create a new group policy object with just the registry settings. The keys you have to change are different for every combination of processor architecture and java architecture. Thus, you have three cases: x64 Windows and x86 Java Set REG_DWORD with name EnableJavaUpdat e located at HKLM\Software\Wow6432Node\JavaSoft\Java Update\Policy to 0 x86 Windows and x86 Java or x64 Windows and x64 Java Set REG_DWORD with name EnableJavaUpdate locate

Paging Command Results in Powershell

When a command has a lot of output, I usually pipe it to Where-Object but it's not always convenient enough... There is a more command to which you can pipe the output of your command but the thing is that the first command has to be run in order to get the output. A workaround for this it to pipe the output to Out-Host -Paging

Windows Explorer related Icons Changed

Strange case today where a user complained about various icons. Indeed, the icons for various folders like "Documents", "Recycle Bin" and "Computer" had changed to an icon that appears on unknown files. After a google search I came across an article that stated that this might be due to a problem with the icon cache. In order to recreate the cache and increase it's size consider the following changes. First of all navigate to the following registry key  HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ Explorer and create a new String Value named  MaxCachedIcons with a value of 2048 . After that, delete the file named  IconCache.db  located under  %userprofile%\AppData\Local  folder. Log the user off and then on and the problem should disappear.

Windows 8 Keyboard Layout Per App

One of the things that was making me crazy every day was the language change in Windows 8. In previous versions of Microsoft Windows, when I changed the keyboard layout in one application and then switched to another the layout automatically changed to the one I had when I was using that application before. In Microsoft Windows 8 and 8.1 when you change the keyboard layout and then switch to another application the layout does not change! Fortunately, there is a setting that allows the previous behavior. You'll find it in Control Panel, All Items View, Language, Advanced Settings on the left side. The checkbox has the title " Let me set a different input method for each app Window".

Active Directory Enterprise CA

In many cases I work with clients that use their own Certification Authority to issue certificates for their services, like Microsoft Exchange, Microsft Lync, IIS websites etc. In order for me to issue a certificate I obviously have to know where I can find the CA server... I use the following command:  certutil -config - -ping  in order to find the CA. If there is a CA with in your network a popup box will appear asking which CA to ping. You then should be able to get the server name from the output that follows on the command prompt.

How to Negate powershell conditions

While developing some new functions for one of my Powershell modules today, I faced the problem where I had to negate one of my functions. To be more specific, I have a function that returns $True if the Powershell session/user has administrator privileges. I then had to display an error cause the function had to be able to access system files. The solution is very simple. Lets say we have the following statement: if (Test-Path C:\Scripts) { Write-Host "Path exists." } and we want to negate it. The only thing we have to do is enclose the Test-Path check into Not function: if (-Not (Test-Path C:\Scripts)) { Write-Error "Path does not exist!" }

Task with Powershell Script Suddenly Started to Fail

Some weeks ago I created a powershell module that contained function to create, view and remove Volume Shadow Copies. I used that module in a script in order to create a new shadow copy and clean up the old ones. I added that script as an action on a Task in Task Scheduler and everything was working fine. After some additions to the module I copied the new file, with the same name, over to the server. I checked the logs a little bit later and there were no new events (my script is writing to a custom log). Then I tried to run the task manually and I got an error code. As it turned out I had to unblock the module file in Windows Explorer in order to avoid the security warning that was waiting for user input from the import-module command. After that everything is working fine again!

PowerShell Log

I'm starting to have many jobs that run powershell scripts on some servers so I decided to update the scripts in order to write to the event logs on the servers. I decided to create my own log in order to be free to do anything I want with it and I called it "Powershell Jobs". I also added a source for every job. All that with the New-EventLog command. I then added error handling code to the scripts using the $error.Count value in order to check if the last command had any errors and the $error[0] for the error message. I then write to the above log using the Write-EventLog command. That way I know what happened for every job and I can get it on Splunk (or any other syslog server) too. One more thing, depending on the result of a command I write error or information events and I'm using a seperate ID for every event type.

NetScaler StoreFront Request Error

We started a Citrix XenDesktop 7.1 installation today and I was the person responsible for the Citrix NetScaler appliances. In that case I had to setup two NetScaler VPX 10 appliances as a High Availability pair, load balance Storefront servers and DDCs and publish the applications and desktops using NetScaler Gateway. I started by downloading the appropriate VM for Hyper-V, created a VM using the vhd (I could not import the VM in Hyper-V 2012 R2 because it was exported from older version of Hyper-V) and then created a clone for the second node. I assigned IP addresses, uploaded license files and created an initial checkpoint of the VMs. I didn't update the firmware cause it was already at the latest version. After that I created the servers for the StoreFront and DDCs and then the Service Groups and the Services on each group. I also load balanced the company's Active Directory servers for the authentication. Then I created the virtual servers, the monitors and the

Office365 DirSync Error

After using dirsync for a few months now in order to sync the on premises Active Directory with the Windows Azure Active Directory for our company's Office 365 subscription, I got a very strange error today. A user reported that she could not log in to her mailbox via Micosoft Outlook so the first thing I did was to check the ForeFront Synchronization Service Manager logs to see if there is something wrong with the password sync process. On the Windows Azure Active Directory Connector there was the message "stopped-extension-dll-exception". The first thing that came to my mind was, OK some update broke the whole thing. I decided to take a look at the Application log in case there's something there that could help, and it was. There were several events stating that there is a error connecting to the authentication service. I searched the web for a bit and there were some people that suggested to check the Azure account used for the process for expired password. I

Citrix NetScaler GUI Error

Upgraded a NetScaler HA pair yesterday, following the official procedure, and everything seemed to be working fine. All services were up, all monitors were fine too. When I tried to take a look on a Virtual Server properties though, I got an error stating that the GUI version that I currently have (124.x) is not compatible with the kernel I'm using (125.8). The message also suggested that I flushed the Java cache, which I have disabled. I gave it a try with other browsers but the result was the same. After googling around for a bit I found out that the problem is caused by a custom theme I have setup on one of my Access Gateway Virtual Servers. I switched the theme setting to Green Bubble and everything works fine now. The bad thing is that I may have to build the custom theme from scratch...

Google Earth 7.1 Group Policy Install

I was asked today to install Google Earth 7.1 on several computers. Since I had deployed the previous version using GPO I though I would give it a try. I downloaded the Google Earth custom installer (left Auto update unchecked) and started the installation. The installer extracts all files in a directory in the %temp% folder so when the extraction is complete go and copy that folder to your desktop. After that, start the administrative install with the command: msiexec -a "Google Earth.msi" When it asks you for a path, enter the network location where you want to have the installation files. Now, when you try to add a package to your group policy object it may fail with an error like the following: "Unable to extract deployment information from the package. Run validation on the package to ensure that the package is correct." In that case fire up orca from the Microsoft Windows SDK, open the msi file on the network location and remove all language codes except 1

Wan Connection Emulation

I wanted to do a POC the other day for a company for the Citrix CloudBridge appliances. I wanted to emulate the satellite connection between the data center and the ships and demonstrate the use of CloudbBridge. After googling around for a bit I stumbled upon  WANem , a linux project that emulates wan connections. I downloaded a copy and fired up a Hyper-V virtual machine using the iso file. I also made a clone of a windows 7 virtual machine that I already had and created a new virtual switch on Hyper-V. I also added two legacy network adapters on the WANem virtual machine because it did not recognize the normal ones. After all virtual machines booted up I had to configure the network settings on all of them. I decided to use the network 10.0.0.0/24 for the data center part and 10.0.1.0/24 for the ship part. After I configured the network on the wanem machine with the appropriate addresses I was time to configure the windows machines. I assigned the proper IPs and set the de

Brackets Installation Error

I was trying to update Brackets today on my machines. The installation of the new package run smoothly on my Windows 7 32bit computer but not so much on the Windows 8.1 x64 computer. After clicking the msi file I got the error that the installation directory (c:\program files (x86)\brackets) has to be on a local drive, which apparently is... I checked the md5 hash of the file and it was fine. After that, I fired up a powershell prompt and changed to the directory of the installation file. I invoked the file and the installation started and there was no error during the process!

Windows Azure Management Certificate

You can always create a self signed certificate using makecert utility that is part of either Visual Studio Tools or Windows SDK. You may find more information on makecert here . I just started the Developer Command Prompt for VS2013, changed to my Desktop and then executed the following command: makecert -sky exchange -r -n "CN=CertificateName" -pe -a sha1 -len 2048 -ss My "CertificateName.cer"  You should replace the "CertificateName" with the name you want for your certificate. I gave it "WindowsAzureManagement". After that you'll have a certificate file on your desktop folder and a new certificate installed under the Personal folder on your User Certificate Store. When you try to add a new Azure Subscription in Visual Studio 2013, through "Manage your subscriptions", you have the new certificate available for the first step. You will also need the certifate file the above command created because you have to uploa