0

I am trying to check the install backup functions and commandline tools are enabled or not.

I've executed Import-ServerManager and ran the necessary commands to enable backup functions, once done I check them:

$BackupFunction = Get-WindowsFeature | Where-Object {$_.Name -eq "Backup"}
$BackupTools = Get-WindowsFeature | Where-Object {$_.Name -eq "Backup-Tools"}
if($BackupFunction.Installed -and $BackupTools.Installed -eq "True")

The code is returning True with same PowerShell window.

But if I close and open a new Powershell then checking again it returns

The term 'Get-WindowFeature' is not recognized..

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
vel
  • 23
  • 9
  • 3
    Check the scope of the `Import-Module ServerManager`. By default, the `Import-Module` cmdlet adds modules to the current session. That means, once, you close the session, the module is lost. Please check and confirm if you are doing the same? – Vivek Kumar Singh Mar 07 '18 at 13:27
  • Thanks Vivek I found the scope of the Import-Module it is survey only current session. we can add to powershell profile to use all sessions but do we have any other command or way to fix this.please advise. – vel Mar 08 '18 at 04:44
  • "Import-Module servermanager -force", "Add-WindowsFeature -Name Backup-Features -includeAllSubFeature", "Add-PSSnapin -Name Windows.ServerBackup" this is commands I need use all the session globally kindly give some suggestion. – vel Mar 08 '18 at 05:36
  • Check out [this](https://stackoverflow.com/questions/20885398/installing-powershell-module-persistently-for-all-users) link. Might solve your issue. – Vivek Kumar Singh Mar 08 '18 at 06:23
  • Thanks but can we add "Add-WindowsFeature -Name Backup-Features -IncludeAllSubFeature" to module ? if not how could i add becasue i have created parts for installbackup and confirmbackup then i calling the parts into component with precheck(if backup function is not installled then install) postcheck (checking backup function is installed or not) i am using start-job for timeout script execution. i have created the profile for this but not working as its creating new job for each execution. this is how i stuck please give some betterment i will try mean time with modules. – vel Mar 08 '18 at 08:50
  • I would suggest you to add `Add-WindowsFeature -Name Backup-Features -IncludeAllSubFeature` as a function and create a `.psm1` file. You can then, follow [this](https://msdn.microsoft.com/en-us/library/dd878350(v=vs.85).aspx) msdn documentation and install the module. After, this is done, your module will then be available for all user sessions. – Vivek Kumar Singh Mar 08 '18 at 10:42

0 Answers0