« Previous Next »

Not Answered Thread: 'Object reference not set to an instance of an object' error in IIS Powershell

Last post 06-12-2009 11:13 AM by Mike C. 18 replies.

Average Rating Rate It (5)

RSS

Page 1 of 2 (19 items) 1 2 Next >

Sort Posts:

  • 05-28-2009, 9:27 AM

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    'Object reference not set to an instance of an object' error in IIS Powershell

    Hi,

    I am new to powershell, I'm looking at it to start streamlining admin tasks on our IIS 7 servers.  When I attempt to run new-item or new-webvirtualdirectory commands I receive the error 'Object reference not set to an instance of an object' error.

    Now, this only appears to happen on IIS servers that have shared config, I have tested the same command on a standalone IIS box and it works with no problem.

    I wonder if I am doing something fundamentally wrong, should I be able to use IIS Powershell to script against a shared config set up?  If so, has anyone seen (and fixed) this issue before?

    The command I am running is:

     new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    The error is:

    New-Item : Object reference not set to an instance of an object.

    I will try some troubleshooting to see if this is a permissions issue but any assistance would be gratefully received.

    Regards,

    Mike.

  • 05-29-2009, 10:50 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    An update - I have taken a shared config IIS server and reverted it back to local config and I still get the problem.  On all our other IIS 7 servers (which have never had shared config) the command works perfectly.  So the shared config thing might be a red herring.

    Next step - to try and recreate the problem on new servers by rebuilding step by step.

    In the meantime, if anyone has any insights they would be gratefully received.

  • 06-02-2009, 8:06 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Another update.  I have tested the following scenarios (all shares are on DFS):

    1. Shared IIS config & shared site files - I get the error.

    2. Local IIS config & local site files - Powershell works fine.

    3. Shared IIS config & local site files - Powershell works fine.

    So the problem appears to lie with using a share to store the site files.

    I will continue to investigate (a security problem perhaps?), in the meantime any help would be appreciated.  Maybe even a 'hello' would do :)

  • 06-02-2009, 8:59 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Microsoft - Please Help!

    I have tested a non-DFS share with 'Everyone-Full Control' on both the share and file permissions and the command still returns the error. 

    I have reached the end of my troubleshooting with the following conclusion:

    The new-webvirtualdirectory command returns the error 'New-Item : Object reference not set to an instance of an object.' when the root of the site is held on a share rather than locally.

    I can recreate this problem and it looks to my untrained eye as though the command cannot deal with the '\\server\share' structure when it comes to the root of the site.

    Microsoft, is there any chance you can have a look at this?  My IIS 7 design uses (DFS) shares for all config to ease management so this is a bit of a show stopper.  Thanks, Mike.

     

  • 06-03-2009, 12:59 PM In reply to

    • sergeia
    • Top 100 Contributor
    • Joined on 04-14-2008, 8:47 PM
    • Posts 68

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Mike, could you please run it again and then post output from

    variable $error[0].Exception.StackTrace?

    This will point me to the location where null pointer is getting hit.

     

    Thanks,

    Sergei

  • 06-03-2009, 1:39 PM In reply to

    • sergeia
    • Top 100 Contributor
    • Joined on 04-14-2008, 8:47 PM
    • Posts 68

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Mike, please tell which installation of IIS snapin do you use, is it installed from the Web site or coming with Windows 7 RC? Also, what kind of connections do you have between two computers, are they joined to domain or members of workgroup? I cannot reproduce this problem between two machines from workgroup, when I point vdir home to the public share of remote server, like \\server_name\users.

     

     Thanks,

    --Sergei

  • 06-04-2009, 4:17 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Hi Sergei,

    I downloaded and installed the IIS Powershell snapin from the website (64 bit edition).  Is it possible I am using thw wrong version?  How can I tell?

    The computers are part of a domain.

    I am going to show my ignorance here, how do I get the output from 'variable $error[0].Exception.StackTrace' when I reproduce the error?

    Thanks for your assistance,

    Mike.

  • 06-04-2009, 5:31 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Hi Sergei, with the help of a few blogs I managed to get the following information from the error:

    Exception             : System.NullReferenceException: Object reference not set to an instance of an object.                           at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetNormalizedRelativePath(String                        path, String basePath)                           at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.ItemExists(String path)                           at System.Management.Automation.Provider.ItemCmdletProvider.ItemExists(String path, CmdletPr                        oviderContext context)                           at System.Management.Automation.SessionStateInternal.ItemExists(CmdletProvider providerInsta                        nce, String path, CmdletProviderContext context)TargetObject          :CategoryInfo          : NotSpecified: (:) [New-Item], NullReferenceExceptionFullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.NewItemCommandErrorDetails          :InvocationInfo        : System.Management.Automation.InvocationInfo  MyCommand        : New-ItemScriptLineNumber : 0OffsetInLine     : 0ScriptName       :Line             :PositionMessage  :InvocationName   :PipelineLength   : 1PipelinePosition : 1 00000000000000000000000000000000000000000000000000000000000000000000000000000000 Message        : Object reference not set to an instance of an object.Data           : {}InnerException :TargetSite     : System.String GetNormalizedRelativePath(System.String, System.String)StackTrace     :    at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetNormalizedRelativePath(String path, S                 tring basePath)                    at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.ItemExists(String path)                    at System.Management.Automation.Provider.ItemCmdletProvider.ItemExists(String path, CmdletProviderC                 ontext context)                    at System.Management.Automation.SessionStateInternal.ItemExists(CmdletProvider providerInstance, St                 ring path, CmdletProviderContext context)HelpLink       :Source         : Microsoft.IIS.Powershell.Provider 

    Is this any help?

    Mike.

  • 06-04-2009, 7:08 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Sergei,

    it is probably worth me being a little clearer on the problem.  The issue only occurs when the web site (e.g. Default Web Site) is set to a share.  Virtual directories under the web site are fine whether they are local or on a share.

     

  • 06-04-2009, 1:46 PM In reply to

    • sergeia
    • Top 100 Contributor
    • Joined on 04-14-2008, 8:47 PM
    • Posts 68

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Mike, you are doing great, but something is still missing here. I still cannot reproduce this issue. And I don't see that ItemExists (that you have in your stack trace) is getting called during processing of new-webvirtualdirectory.

    Let's start full scale attack on this. Please provide answers to following questions:

    1. Which version of PowerShell are you using? Is it version 1 or version 2?

    2. Please describe your setup in full details, you could use any names, I am interested in 'topology': which share is used for configuration, which share is used for parent site home path, which share is passed as home for new vdir?

    3. Make sure you could see the site and folder under it. Run 'dir iis:\sites' and 'dir iis:\sites\parentSite' -- there should be no errors.

    4. Make sure you could see home folder for new vdir. For this share please run 'dir \\machine\share' -- there should be no errors.

    5. Please provide full command line you are using for new vdir, including prompt, like 'PS C:\ #> new-webvirtualdirectory -site testSite -name shared2 -physicalpath \\sergeia-dev32\config'.

    6. After you get an error, please type '$StackTrace' and show me output from it. $StackTrace is PowerShell global variable that is shortcut for $error[0].Exception.StackTrace, and contains managed stack trace for the last error that happened. Previous one will be in $error[1], etc.

     

    Thanks,

    Sergei

  • 06-08-2009, 4:41 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Hi Sergei,

    thanks for your continued assistance, the answers (hopefully) to your questions are below.  There are some errors which I have highlighted in bold.  I have also provided the $StackTrace for each of these errors at the end.

    1. Which version of PowerShell are you using? Is it version 1 or version 2?

    PS IIS:\> get-host

    Name             : ConsoleHost

    Version          : 1.0.0.0

    InstanceId       : 6f6cc0c1-9373-4b94-b69d-669f6669bc43

    UI   : System.Management.Automation.Internal.Host.InternalHostUserInterface

    CurrentCulture   : en-GB

    CurrentUICulture : en-US

    PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy

     

    2. Please describe your setup in full details, you could use any names, I am interested in 'topology': which share is used for configuration, which share is used for parent site home path, which share is passed as home for new vdir?

    2 x W2K8 SP1 DFS servers: DWEB04 and DWEB05

    DFS Namespace: \\alliance\DWEBDFS02

    DFS Shares: IISConfig, IISApps

    2 x W2K8 SP1 IIS servers: DWEB07 and DWEB08

    IIS Shared Config Physical Path: \\alliance\dwebdfs02\IISConfig\V1.0

    IIS Sites: Default Web Site

    Default Web Site Physical Path: \\alliance\dwebdfs02\iisapps\Root-DefaultWebSite\v1.0

    New Virtual Directory Physical Path – Have tried the following (both local and shared) and still get the error:

    -      C:\

    -      \\alliance\dwebdfs02\iisapps\TestWACSFullTrust\1.1.0.0\

    3. Make sure you could see the site and folder under it. Run 'dir iis:\sites' and 'dir iis:\sites\parentSite' -- there should be no errors.

    Output from ‘dir iis:sites’:

    Name             ID   State      Physical Path                  Bindings

    ----             --   -----      -------------                  --------

    Default Web Site 1    Started    \\alliance\dwebdfs02\iisapps\R http *:80:

                                     oot-DefaultWebSite\v1.0

    Output from ‘dir iis:\sites\parentSites’

    Get-ChildItem : Cannot find path '\\DWEB07\sites\parentSites' because it does not exist.

    At line:1 char:4

    + dir  <<<< iis:\sites\parentSites:

     

    4. Make sure you could see home folder for new vdir. For this share please run 'dir \\machine\share' -- there should be no errors.

    Output for dir c:\

        Directory: Microsoft.PowerShell.Core\FileSystem::C:\

    Mode                LastWriteTime     Length Name

    ----                -------------     ------ ----

    d----        03/04/2009     10:57            inetpub

    d----        19/01/2008     10:11            PerfLogs

    d-r--        29/05/2009     15:20            Program Files

    d-r--        07/05/2009     14:31            Program Files (x86)

    d----        15/05/2009     12:39            temp

    d-r--        20/05/2009     15:19            Users

    d----        20/05/2009     15:20            Windows

    -ar-s        03/04/2009     19:06       8192 BOOTSECT.BAK

    -a---        22/04/2009     10:29         21 tmuninst.ini

    Output for dir \\alliance\dwebdfs02\iisapps\TestWACSFullTrust\1.1.0.0\:

    Get-ChildItem : Object reference not set to an instance of an object.

    At line:1 char:4

    + dir  <<<< \\alliance\dwebdfs02\iisapps\TestWACSFullTrust\1.1.0.0\

    (Note, if I browse to this location in Explorer I can see it with no problem.  I have tried this command against a number of DFS and non-DFS shares on our network and I get the same error.)

     

    5. Please provide full command line you are using for new vdir, including prompt, like 'PS C:\ #> new-webvirtualdirectory -site testSite -name shared2 -physicalpath \\sergeia-dev32\config'.

    PS IIS:\> new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    PS IIS:\> new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath \\alliance\dwebdfs02\iisapps\TestWACSFullTrust\1.1.0.0\

     

    6. After you get an error, please type '$StackTrace' and show me output from it. $StackTrace is PowerShell global variable that is shortcut for $error[0].Exception.StackTrace, and contains managed stack trace for the last error that happened. Previous one will be in $error[1], etc.

    The output from each of the errors I received going through these six steps:

    Command - PS IIS:\> new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    Error trace - PS IIS:\> $StackTrace

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetNormalizedRelativePath(String path, String basePath)

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.ItemExists(String path)

       at System.Management.Automation.Provider.ItemCmdletProvider.ItemExists(String path, CmdletProviderContext context)

       at System.Management.Automation.SessionStateInternal.ItemExists(CmdletProvider providerInstance, String path, CmdletProviderContext context)

    Command – PS IIS:\> new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath \\alliance\dwebdfs02\iisapps\TestWACSFullTrust\1.1.0.0\

    Error trace - PS IIS:\> $StackTrace

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetNormalizedRelativePath(String path, String basePath)

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.ItemExists(String path)

       at System.Management.Automation.Provider.ItemCmdletProvider.ItemExists(String path, CmdletProviderContext context)

       at System.Management.Automation.SessionStateInternal.ItemExists(CmdletProvider providerInstance, String path, CmdletProviderContext context)

    Command - PS IIS:\> dir \\alliance\dwebdfs02\iisapps\TestWACSFullTrust\1.1.0.0\

    Error trace - PS IIS:\> $StackTrace

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetNormalizedRelativePath(String path, String basePath)

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.ItemExists(String path)

       at System.Management.Automation.Provider.ItemCmdletProvider.ItemExists(String path, CmdletProviderContext context)

       at System.Management.Automation.SessionStateInternal.ItemExists(CmdletProvider providerInstance, String path, Cmdlet

    ProviderContext context)

    Command - PS IIS:\> dir iis:\sites\parentSites

    Error Trace - PS IIS:\> $StackTrace

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetNormalizedRelativePath(String path, String basePath)

       at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.ItemExists(String path)

       at System.Management.Automation.Provider.ItemCmdletProvider.ItemExists(String path, CmdletProviderContext context)

       at System.Management.Automation.SessionStateInternal.ItemExists(CmdletProvider providerInstance, String path, CmdletProviderContext context)

    I hope this all helps!

    Mike.

  • 06-08-2009, 8:35 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Hi Sergei,

    as I now have a few more commands (that you taught me!) I re-ran some of my tests.  I ran four scenarios with a new IIS7 server (DWAR02).  Each scenario had 5 tests, the results are below.

    The results confirm my findings, that when the physical path of the 'Default Web Site' is on a share I cannot run the create virtual directory command.  When the physical path is local, the command works fine.  There does not appear to be any issue with the location of the virtual directory itself (local or share) or the IIS config files.

    Interestingly the dir iis:\sites\parentsites command errors all the time, as does the dir command when looking at a share.

    DWAR02 Tests

    Stage 1 - IIS Standard build:

    IIS Config Physical Path: Local

    IIS Sites: Default Web Site

    Default Web Site Physical Path: %SystemDrive%\inetpub\wwwroot

    Test 1: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    Outcome: Virtual Directory created successfully

    Test 2: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: Virtual Directory created successfully

    Test 3: dir file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: Get-ChildItem : Object reference not set to an instance of an object.

    Test 4: dir iis:\sites

    Outcome:

    Name             ID   State      Physical Path                  Bindings

    ----             --   -----      -------------                  --------

    Default Web Site 1    Started    %SystemDrive%\inetpub\wwwroot  http *:80:

    Test 5: dir iis:\sites\parentSites

    Outcome: Get-ChildItem : Cannot find path '\\DWAR02\sites\ParentSites' because it does not exist.

    Stage 2 - Added to Shared Config (as per previous post above):

    IIS Shared Config Physical Path: \\alliance\dwebdfs02\IISConfig\V1.0

    IIS Sites: Default Web Site

    Default Web Site Physical Path: \\alliance\dwebdfs02\iisapps\Root-DefaultWebSite\v1.0

    Test 1: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    Outcome: New-Item : Object reference not set to an instance of an object. (Different from Stage 1)

    Test 2: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: New-Item : Object reference not set to an instance of an object. (Different from Stage 1)

    Test 3: dir file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: Get-ChildItem : Object reference not set to an instance of an object. (Same as Stage 1)

    Test 4: dir iis:\sites

    Outcome:

    Name             ID   State      Physical Path                  Bindings

    ----             --   -----      -------------                  --------

    Default Web Site 1    Started    file://alliance/\dwebdfs02\iisapps\R http *:80:

                                     oot-DefaultWebSite\v1.0

    Test 5: dir iis:\sites\parentSites

    Outcome: Get-ChildItem : Cannot find path ‘\\DWAR02\sites\ParentSites' because it does not exist. (Same as Stage 1)

    Stage 3 - Removed from Shared Config BUT retaining shared config settings:

    IIS Config Physical Path: Local

    IIS Sites: Default Web Site

    Default Web Site Physical Path: \\alliance\dwebdfs02\iisapps\Root-DefaultWebSite\v1.0

    Test 1: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    Outcome: New-Item : Object reference not set to an instance of an object. (same as Stage 2)

    Test 2: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: New-Item : Object reference not set to an instance of an object. (Same as Stage 2)

    Test 3: dir file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: Get-ChildItem : Object reference not set to an instance of an object. (Same as Stage 1 and Stage 2)

    Test 4: dir iis:\sites

    Outcome:

    Name             ID   State      Physical Path                  Bindings

    ----             --   -----      -------------                  --------

    Default Web Site 1    Started    file://alliance/\dwebdfs02\iisapps\R http *:80:

                                     oot-DefaultWebSite\v1.0

    Test 5: dir iis:\sites\parentSites

    Outcome: Get-ChildItem : Cannot find path ‘\\DWAR02\sites\ParentSites' because it does not exist. (Same as Stage 1 and Stage 2)

    Stage 4 - Default Web Site physical path set local:

    IIS Config Physical Path: Local

    IIS Sites: Default Web Site

    Default Web Site Physical Path: %SystemDrive%\inetpub\wwwroot

    Test 1: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\

    Outcome: Virtual Directory created successfully

    Test 2: new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: Virtual Directory created successfully

    Test 3: dir file://alliance/dwebdfs02/iisapps/TestWACSFullTrust/1.1.0.0/

    Outcome: Get-ChildItem : Object reference not set to an instance of an object. (Same as Stage 1 and Stage 2 and Stage 3)

    Test 4: dir iis:\sites

    Outcome:

    Name             ID   State      Physical Path                  Bindings

    ----             --   -----      -------------                  --------

    Default Web Site 1    Started    %SystemDrive%\inetpub\wwwroot  http *:80:

    Test 5: dir iis:\sites\parentSites

    Outcome: Get-ChildItem : Cannot find path ‘\\DWAR02\sites\ParentSites' because it does not exist. (Same as Stage 1 and Stage 2 and Stage 3)

  • 06-09-2009, 4:08 AM In reply to

    • Mike C
    • Not Ranked
    • Joined on 05-28-2009, 9:16 AM
    • Posts 13

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Hi Sergei,

    I have installed Powershell 2.0 CTP3 on one of the IIS servers and I still have the same problem (although the error reporting is better!):

    PS IIS:\> new-webvirtualdirectory -site "Default Web Site" -name MCTest -physicalpath c:\
    New-Item : Object reference not set to an instance of an object.
        + CategoryInfo          : NotSpecified: (:) [New-Item], NullReferenceException
        + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.NewItemCommand

  • 06-09-2009, 11:13 AM In reply to

    • sergeia
    • Top 100 Contributor
    • Joined on 04-14-2008, 8:47 PM
    • Posts 68

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Mike, do you mind to provide answers to questions I asked you in my last reply? Without looking at the wider picture we cannot move forward, just sending me failed command doesn't help -- I need more complete description of your setup.

    Thanks,

    Sergei

  • 06-09-2009, 11:15 AM In reply to

    • sergeia
    • Top 100 Contributor
    • Joined on 04-14-2008, 8:47 PM
    • Posts 68

    Re: 'Object reference not set to an instance of an object' error in IIS Powershell

    Nevermind, I see that you already sent these replies. I will try to reproduce it here.

    --Sergei

Page 1 of 2 (19 items) 1 2 Next >
Microsoft Communities