Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Resource name 'Archive' is already being used by another Resource or Configuration. #184

Open
NemoDima opened this issue Mar 25, 2020 · 8 comments
Labels
question The issue is a question.

Comments

@NemoDima
Copy link

NemoDima commented Mar 25, 2020

Resource name 'Archive' is already being used by another Resource or Configuration.
As I understand, problem same as #88

Details of the scenario you tried and the problem that is occurring

Try to run generate MOF-files

Verbose logs showing the problem

At line:8 char:5
+     Import-DscResource -ModuleName PSDscResources
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Resource name 'Archive' is already being used by another Resource or Configuration.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : DuplicateKeywordDefinition

Suggested solution to the issue

N/A

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration Basic_settings
{
    Import-DSCResource -ModuleName ComputerManagementDsc #For Powerplan, PagingSettings, SetTimeZone
    Import-DSCResource -ModuleName LanguageDsc #For SetLanguage
    Import-DSCResource -ModuleName PSDesiredStateConfiguration
    Import-DSCResource -ModuleName xChrome #To Install latest Chrome browser
    Import-DSCResource -ModuleName xRemoteDesktopSessionHost #For RDP
    Import-DscResource -ModuleName PSDscResources
    Import-DSCResource -ModuleName NetworkingDsc #For Firewall rules
    Import-DscResource -ModuleName SecurityPolicyDsc #For AccountPolicy
    Import-DSCResource -ModuleName StorageDsc #For ISO-mounting
    Import-DSCResource -ModuleName SqlServerDsc #For SQL

    Node "localhost"
    {
        $password = "123456" | ConvertTo-SecureString -asPlainText -Force
        $username = "test"
        [PSCredential] $credential = New-Object System.Management.Automation.PSCredential($username,$password)

        $FTPpassword = "Backup" | ConvertTo-SecureString -asPlainText -Force
        $FTPusername = "Ftp"
        [PSCredential] $FTPcredential = New-Object System.Management.Automation.PSCredential($FTPusername,$FTPpassword)

        $servername = 'testserver'
        $workgroupname = 'company'

        Computer SetNameandWorkgroup
        {
            Name          = $servername
            WorkGroupName = $workgroupname
        }

        PowerPlan SetPlanHighPerformance
        {
            IsSingleInstance = 'Yes'
            Name             = 'High performance'
        }

        # "Adjust for best performance" https://github.com/dsccommunity/ComputerManagementDsc/issues/320
        # "Processor scheduling" to Programs https://github.com/dsccommunity/ComputerManagementDsc/issues/321
        
        VirtualMemory PagingSettings
        {
            Type             = 'AutoManagePagingFile'
            Drive            = 'C'
        }
        
        TimeZone SetTimeZone
        {
            IsSingleInstance = 'Yes'
            TimeZone         = 'FLE Standard Time'
            #adjust to daylight ON ?? 
        }
        #SystemLocale SetSystemLocale
        #{
         #   IsSingleInstance = 'Yes'
         #   SystemLocale = 'ru-RU'
            #Get all available SystemLocale 
            #[System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures).name 

        #}
        
        Language SetLanguage
        {
            IsSingleInstance = 'Yes'
            LocationID = 203
            SystemLocale = 'ru-RU'
            AddInputLanguages = @("0419:00000419")
            UserLocale = 'ru-RU'
            CopySystem = $true
            CopyNewUser = $true
        }
        
        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
            ActionAfterReboot = 'ContinueConfiguration'
            ConfigurationMode = 'ApplyAndAutoCorrect'
        }
        
        Registry ChangeDecimalSymbol  #Change Decimal symbol to "."
        {
            Key = 'HKCU:\Control Panel\International'
            Ensure = 'Present'
            ValueName = 'sDecimal'
            #ValueType = 'Binary'
            ValueData = '.'
            Force = $true
            PsDscRunAsCredential = $credential
        }
        
        Registry ChangeLanguageBarHotKey  #Change language bar hotkey to Ctrl-Shift
        {
            Key = 'HKCU:\Keyboard Layout\Toggle'
            Ensure = 'Present'
            ValueName = 'Language Hotkey'
            #ValueType = 'Binary'
            ValueData = '2'
            Force = $true
            PsDscRunAsCredential = $credential
        }
        
        User UserExample
        {
            Ensure = "Present"  # To ensure the user account does not exist, set Ensure to "Absent"
            UserName = "FtpBackup"
            FullName = "FtpBackup"
            Description = "GoodStream"
            Password = $FTPcredential # This needs to be a credential object
            PasswordNeverExpires = $true
            #DependsOn = "[Group]GroupExample" # Configures GroupExample first
        }
        
#        Group FTPBackup 
#        {
#            GroupName        = 'FTPBackup'
#            Ensure           = 'Present'
#            MembersToInclude = 'FtpBackup'
#            DependsOn = '[User]UserExample'
#            #Credential =  $credential #$null #
#        }
        #---------------- Install software ------
        MSFT_xChrome InstallChrome
        {
            #Language = 'eng'#$Language
            #LocalPath = $LocalPath
        }

        MSIPackage 7-Zip
        {
            Ensure = 'Present'
            #Name = '7-Zip 19.00 (x64 edition)'
            #Path = 'C:\Install\Software\7z1900-x64.msi'
            Path = 'https://www.7-zip.org/a/7z1900-x64.msi'
            ProductId = '23170F69-40C1-2702-1900-000001000000'
            Arguments = '/qn /norestart'
        }

        MSIPackage Notepad++ # msi file published by https://www.hass.de
        {
            Ensure = 'Present'
            #Name = 'Notepad++ 7.5.5 (x64)'
            Path = 'C:\Install\Software\npp.7.5.5.installer.x64.mui.msi'
            ProductId = '178B66BE-A604-4983-8633-742FBD73F629'
            Arguments = '/qn /norestart'
        }

        
        #---------------- RDP ------------------
        
        WindowsFeatureSet InstallRDS
        {
            # Install Desktop Licensing and Remote Desktop Session Host from Remote Desktop Services
            Name = @('RDS-Connection-Broker', 'RDS-Licensing', 'RDS-RD-Server')
            Ensure = 'Present'            
        }

        # GPO settings for RDS licensing server https://github.com/dsccommunity/xRemoteDesktopSessionHost/issues/76
        #xRDLicenseConfiguration SetRDPLicensingSettings
        #{
        #    ConnectionBroker = $servername
        #    LicenseMode = 'PerDevice'
        #    DependsOn = '[WindowsFeatureSet]InstallRDS'
        #    LicenseServer = $servername
        #    PsDscRunAsCredential = $credential
        #}
                     
        # RDS licensing https://github.com/dsccommunity/xRemoteDesktopSessionHost/issues/64

        # открыть новый порт в файерволе https://github.com/dsccommunity/NetworkingDsc/wiki/Firewall
        Firewall AddNewRDPPortRule
        {
            Name                  = 'RDPNew'
            DisplayName           = 'RDPNew'
            #Group                 = 'NotePad Firewall Rule Group'
            Ensure                = 'Present'
            Enabled               = 'True'
            Profile               = ('Domain', 'Private', 'Public')
            Direction             = 'Inbound'
            #RemotePort            = ('8080', '8081')
            LocalPort             = '32154'
            Protocol              = 'TCP'
            Description           = 'Firewall Rule for New RDP Port'
            #Program               = 'c:\windows\system32\notepad.exe'
            #Service               = 'WinRM'
        }

        # сменить рдп порт в реестре
        #Registry ChangeLanguageBarHotKey 
        #{
        #    Key = 'HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp'
        #    Ensure = 'Present'
        #    ValueName = 'PortNumber'
        #    ValueType = 'Decimal'
        #    ValueData = '32154'
        #    Force = $true
        #    PsDscRunAsCredential = $credential
        #}

        # изменить настройки безопасности в Audit Policy https://github.com/dsccommunity/AuditPolicyDsc/issues/57  

        # изменить настройки безопасности в Account Policies
        AccountPolicy SetAcountPolicyForRDP
        {
            Name = 'ForRDP'
            Account_lockout_threshold = 5
            Maximum_Password_Age = 0
        }

        SecurityOption SetSecurityPolicyForRDP
        {
            Name = 'ForRDP'
            Accounts_Limit_local_account_use_of_blank_passwords_to_console_logon_only = 'Enabled'
            # https://lancloud.ru/articles/oshibka-pri-podklyuchenii-po-rdp-ispravlenie-shifrovaniya-credssp/
            #Network_Security_Restrict_NTLM_Incoming_NTLM_Traffic = 'Deny all accounts'
        }


        # отключить старый порт для рдп в файерволе
        #Firewall DisableDefaultRDPPortRule1
        #{
        #    Name                  = 'Remote Desktop - User Mode (TCP-In)'
        #    DisplayName           = 'Remote Desktop - User Mode (TCP-In)'
        #    #Group                 = 'NotePad Firewall Rule Group'
        #    Ensure                = 'Present'
        #    Enabled               = 'False'
        #    #Profile               = ('Domain', 'Private', 'Public')
        #    Direction             = 'Inbound'
        #    #RemotePort            = ('8080', '8081')
        #    LocalPort             = '3389'
        #    Protocol              = 'TCP'
        #    #Description           = 'Firewall Rule for New RDP Port'
        #    #Program               = 'c:\windows\system32\notepad.exe'
        #    #Service               = 'WinRM'
        #}

        #Firewall DisableDefaultRDPPortRule2
        #{
        #    Name                  = 'Remote Desktop Services - User Mode (TCP-In)'
        #    DisplayName           = 'Remote Desktop Services - User Mode (TCP-In)'
        #    #Group                 = 'NotePad Firewall Rule Group'
        #    Ensure                = 'Present'
        #    Enabled               = 'False'
        #    #Profile               = ('Domain', 'Private', 'Public')
        #    Direction             = 'Inbound'
        #    #RemotePort            = ('8080', '8081')
        #    LocalPort             = '3389'
        #    Protocol              = 'TCP'
        #    #Description           = 'Firewall Rule for New RDP Port'
        #    #Program               = 'c:\windows\system32\notepad.exe'
        #    #Service               = 'WinRM'
        #}
         

        #---------------- SQL install ----------
         MountImage MountMSSQL2016
        {
            ImagePath   = 'C:\Install\Software\Microsoft SQL Server 2016 RTM with SP2 (MSDN)\en_sql_server_2016_enterprise_core_with_service_pack_2_x64_dvd_12124052.iso'
            DriveLetter = 'S'
            Ensure = 'Present'
        }

        WaitForVolume WaitForISO
        {
            DriveLetter      = 'S'
            RetryIntervalSec = 5
            RetryCount       = 10
            DependsOn = '[MountImage]MountMSSQL2016'
        }

        SqlSetup InstallMSSQL2016 #ResourceName 
		# "Grant perform Volume Maintenance Task ... " option,  question https://github.com/dsccommunity/SqlServerDsc/issues/1481
        {
            ProductKey = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
            InstanceName = 'TEST_MSSQLSERVER'
            Action = 'Install'
            UpdateEnabled = $false
            # components codes http://sqldatapartners.com/2015/03/26/abbreviations-for-sql-server-components-when-installing-with-powershell/
            Features = 'SQLENGINE,CONN,BC,SDK'
            #InstanceDir = 'C:\Program Files\Microsoft SQL Server'
            InstanceDir = 'C:\TestMSSQL\InstanceDir'
            #InstallSharedDir = 'C:\Program Files\Microsoft SQL Server'
            InstallSharedDir = 'C:\TestMSSQL\InstallSharedDir'
            #InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server'
            InstallSharedWOWDir = 'C:\TestMSSQL\InstallSharedWOWDir'
            AgtSvcStartupType = 'Automatic'
            SqlSvcStartupType = 'Automatic'
            BrowserSvcStartupType = 'Disabled'
            # set grant perform volume maintenance task privilege to sql server database engine ?
            SQLCollation = 'Cyrillic_General_CI_AS'
            SecurityMode = 'SQL' #Mixed mode
            PsDscRunAsCredential = $credential
            SQLSvcAccount = $credential
            AgtSvcAccount = $credential
            SAPwd = $credential
            # SQLSysAdminAccounts = [string[]] список админов
            #[InstallSQLDataDir = [string]]
            #SQLUserDBDir = 'C:\Program Files\Microsoft SQL Server\MSSQL13.SSSS\MSSQL\Data'
            SQLUserDBDir = 'C:\TestMSSQL\SQLUserDBDir'
            #SQLUserDBLogDir = 'C:\Program Files\Microsoft SQL Server\MSSQL13.SSSS\MSSQL\Data'
            SQLUserDBLogDir = 'C:\TestMSSQL\SQLUserDBLogDir'
            #SQLBackupDir = 'C:\Program Files\Microsoft SQL Server\MSSQL13.SSSS\MSSQL\Backup'
            SQLBackupDir = 'C:\TestMSSQL\SQLBackupDir'
            #SQLTempDBDir = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data'
            SQLTempDBDir = 'C:\TestMSSQL\SQLTempDBDir'
            #SQLTempDBLogDir = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data'
            SQLTempDBLogDir = 'C:\TestMSSQL\SQLTempDBLogDir'

            SourcePath = 'S:\'
            
            ForceReboot = $false
            #[SuppressReboot = [bool]]
            
 # ----
#            [ASBackupDir = [string]]
#            [ASCollation = [string]]
#            [ASConfigDir = [string]]
#            [ASDataDir = [string]]
#            [ASLogDir = [string]]
#            [ASServerMode = [string]{ MULTIDIMENSIONAL | POWERPIVOT | TABULAR }]
#            [ASSvcAccount = [PSCredential]]
#            #AsSvcStartupType = 'Automatic'
#            [ASSysAdminAccounts = [string[]]]
#            [ASTempDir = [string]]
#            [DependsOn = [string[]]]
#            [ErrorReporting = [string]]
#            [FailoverClusterGroupName = [string]]
#            [FailoverClusterIPAddress = [string[]]]
#            [FailoverClusterNetworkName = [string]]
#            [FeatureFlag = [string[]]]
#            [FTSvcAccount = [PSCredential]]
#            [InstanceID = [string]]
#            [ISSvcAccount = [PSCredential]]
#            [IsSvcStartupType = [string]{ Automatic | Disabled | Manual }]
#            [PsDscRunAsCredential = [PSCredential]]
#            [RSInstallMode = [string]{ DefaultNativeMode | FilesOnlyMode | SharePointFilesOnlyMode }]
#            [RSSvcAccount = [PSCredential]]
#            [RSSVCStartupType = [string]{ Automatic | Disabled | Manual }]
#            [SetupProcessTimeout = [UInt32]]
#            [SourceCredential = [PSCredential]]
#            #SqlSvcStartupType = 'Automatic'
#            [SqlTempdbFileCount = [UInt32]]
#            [SqlTempdbFileGrowth = [UInt32]]
#            [SqlTempdbFileSize = [UInt32]]
#            [SqlTempdbLogFileGrowth = [UInt32]]
#            [SqlTempdbLogFileSize = [UInt32]]
#            [SQMReporting = [string]]
#            [UpdateSource = [string]]
        }

        #MountImage DismountMSSQL2016 bugreport https://github.com/dsccommunity/StorageDsc/issues/226
        #{
        #    ImagePath   = 'C:\Install\Software\Microsoft SQL Server 2016 RTM with SP2 (MSDN)\en_sql_server_2016_enterprise_core_with_service_pack_2_x64_dvd_12124052.iso'
        #    DriveLetter = 'S'
        #    Ensure = 'Absent'
        #}

        #MsiPackage unintsallSSMS # get SSMS.msi folowing instruction: https://serverfault.com/questions/907771/how-to-install-ssms-on-a-client-workstation-using-azure-automation-ds 
        #{
        #    Ensure = 'Absent'
        #    #Name = 'SQL Server Management Studio'
        #    Path = 'C:\Install\Software\sql_ssms.msi'
        #    ProductId = '3E532AF4-B9B1-4DE0-9511-7ACEB14C8D6D'
        #    #Arguments = '/qn /norestart'
        #}

        MsiPackage SSMS # get SSMS.msi folowing instruction: https://serverfault.com/questions/907771/how-to-install-ssms-on-a-client-workstation-using-azure-automation-ds 
        {
            Ensure = 'Present'
            #Name = 'SQL Server Management Studio'
            Path = 'C:\Install\Software\sql_ssms.msi'
            ProductId = '3E532AF4-B9B1-4DE0-9511-7ACEB14C8D6D'
            Arguments = '/qn /norestart'
        }
                
        # install SSMS, request https://github.com/dsccommunity/SqlServerDsc/issues/125
         
        #------------sites-----

        #Rights for the folder https://github.com/dsccommunity/FileSystemDsc

        #-----------windows updates
        # https://github.com/dsccommunity/xWindowsUpdate
    }
}

$configData = @{
    AllNodes = @(
        @{
            NodeName = '*'
            PSDscAllowPlainTextPassword = $True
            PsDscAllowDomainUser = $true   
        }
        @{
            NodeName = 'localhost'
            PSDscAllowPlainTextPassword = $True
            PsDscAllowDomainUser = $true   
        }
    )
}

Basic_settings -OutputPath "C:\DSC\Configurations" -ConfigurationData $configData

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.1794.amd64fre.rs1_release.171008-1615
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

PSVersion                      5.1.14393.1884                                                                        
PSEdition                      Desktop                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                               
BuildVersion                   10.0.14393.1884                                                                       
CLRVersion                     4.0.30319.42000                                                                       
WSManStackVersion              3.0                                                                                   
PSRemotingProtocolVersion      2.3                                                                                   
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

current

@PlagueHO PlagueHO added the question The issue is a question. label Apr 2, 2020
@PlagueHO
Copy link
Contributor

PlagueHO commented Apr 2, 2020

Hi @NemoDima - sorry about the delay in getting back to you.

This is because you're importing both PSDesiredStateConfiguration and PSDscResources into the same configuration.

PSDscResources is a complete replacement for PSDesiredStateConfiguration. Just import the newer PSDscResources and remove the Import-DscResource PSDesiredStateConfiguration.

@richardgavel
Copy link

Is there any way to suppress, then, the following Warning?

WARNING: The configuration 'xxx' is loading one or more built-in resources without explicitly importing associated modules. Add Import-DscResource -ModuleName 'PSDesiredStateConfiguration' to your configuration to avoid this message.

@PlagueHO
Copy link
Contributor

Can you share your configuration @richardgavel ?

@bjoernf73
Copy link

Hi @NemoDima - sorry about the delay in getting back to you.

This is because you're importing both PSDesiredStateConfiguration and PSDscResources into the same configuration.

PSDscResources is a complete replacement for PSDesiredStateConfiguration. Just import the newer PSDscResources and remove the Import-DscResource PSDesiredStateConfiguration.

No - it is NOT a replacement. The PSDscResources is supposed to overwrite resources in the built-in PSDesiredStateConfiguration (according to https://github.com/PowerShell/PSDscResources) - but it does not export any commands or cmdlets. So whenever you use Start-DscConfiguration or Publish-DscConfiguration, the PSDesiredStateConfiguration module loads.
ExportedCmdlets

@ZianAtFirstWatch
Copy link

Can you share your configuration @richardgavel ?

I was able to reproduce the problem by creating a configuration with a File resource.

You can see the it by opening the following file with PowerShell ISE and clicking the Run Script button in the toolbar.

PowerShell will say:

At C:\Users\zchoy\Desktop\Example Configuration.ps1:5 char:5
+     Import-DscResource -ModuleName 'PSDscResources'
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Resource name 'Archive' is already being used by another Resource or Configuration.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : DuplicateKeywordDefinition

Then, uncomment the first import (PSDesiredStateConfiguration) and press Run Script again.

Now, it will run successfully but PowerShell will show a different message.

WARNING: The configuration 'EnvironmentVariable_Path' is loading one or more built-in resources without explicitly importing associated modules. Add Import-DscResource –ModuleName 'PSDesiredStateConfiguration' to your configuration to avoid this message.

@ZianAtFirstWatch
Copy link

I've attached the file inside a ZIP file.

When I tried to share the PS1 file, GitHub said "We don't support that file type. Try again with a GIF, JPEG, JPG, MOV, MP4, PNG, SVG, WEBM, CSV, DOCX, FODG, FODP, FODS, FODT, GZ, LOG, MD, ODF, ODG, ODP, ODS, ODT, PATCH, PDF, PPTX, TGZ, TXT, XLS, XLSX, or ZIP."
Example Configuration.zip

@johlju
Copy link
Contributor

johlju commented Jul 5, 2023

This is the code in the zip file above.

Configuration NotepadDemo
{
    param ()
    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'PSDscResources'

    Node localhost
    {
      
        File Notepad {
			DestinationPath ="C:\Windows\notepad.exe"
            Ensure      ="Present"
        }
    }
}

NotepadDemo

@johlju
Copy link
Contributor

johlju commented Jul 5, 2023

You have to remove the import of PSDesiredStateConfiguration in this case, and just ignore the warning message that is outputted. This is because the File resource is not part of PSDscResource.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question The issue is a question.
Projects
None yet
Development

No branches or pull requests

6 participants