Powershell IIS add authentication user RRS feed

  • General discussion

  • I am trying to add some authenticated users (with the name from $description) to my FTP server using Powershell, but I can't figure out how to do it. This is the code I am trying to use:

        Invoke-Command -ComputerName WIN-SERV2 -ArgumentList $description -ScriptBlock { Add-WebConfiguration -Filter "/system.ftpserver/authorization/*" -Force -Location '$FTPserver/$VDir' -PSPath 'IIS:\Sites\$FTPserver' -Value (@{accessType='Allow';permissions='Read,Write';users=$args[0]}) }            

    When I run the code nothing happens on the IIS server, the user is not in the authorization rules. I do not get any errors.

    The server i am running this on is my domain contoler because I am creating other files and things. I am able to acces the FTP server from my domain controller because I can create a folder on the FTP server.

    Bouth server are running windows server 2016, but are not connected to the internett.

    I dont know what more info to give but just ask if you need more!

    • Changed type Bill_Stewart Tuesday, December 5, 2017 3:22 PM
    • Moved by Bill_Stewart Tuesday, December 5, 2017 3:23 PM This is not IIS support forum
    Wednesday, November 1, 2017 9:22 AM

All replies

  • This is not an IIS management forum.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, November 1, 2017 2:19 PM
  • First you need to write your code so that it is readable and you need to use the correct quoting methods.

    $sb = {
        $props = @{
            Filter = '/system.ftpserver/authorization/*'
            Force  = $true
            Location = "$FTPserver/$VDir"
            PSPath = "IIS:\Sites\$FTPserver"
            Value = @{ 
                accessType = 'Allow';
                permissions = 'Read,Write';
                Users = $args[0] 
        Add-WebConfiguration @props
    Invoke-Command -ScriptBlock $sb -ArgumentList $description -ComputerName WIN-SERV2

    Bill is correct in noting that you need to post in the IIS forum with IIS configuration issue: http://forums.iis.net


    Wednesday, November 1, 2017 3:52 PM
  • Hi,

    Sorry for taking so long to respond. I tryed the code and it did not work. I then tryed the code on my IIS server and got this error message:

    Add-WebConfiguration : Object reference not set to an instance of an object.
    At line:12 char:7
    +             Add-WebConfiguration @props
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Add-WebConfiguration], NullReferenceException
        + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.IIs.PowerShell.Provider.AddConfigurationCommand

    I did not use invoke-command. a quick google told me that there maby was something that i need to configure, but i dont know how to or where to configure what ever i need to configure.

    Ill try to ask on the IIS forum insted if that is better.

    • Edited by Tobhal Monday, November 6, 2017 8:17 AM
    Monday, November 6, 2017 8:15 AM