I'm trying to run some powershell scripts from a Centos box. I have installed powershell successfully and have then further obtained the scripts i wish to run.
in powershell i have run:
Import-PowershellDataFile ./tools/powershell/DhcpServer.psd1
Then i have tried to use:
Get-DhcpServerv4Scope -ComputerName 10.66.56.66
i have imported the following into my folder /tools/powershell:
DhcpServer.psd1
DhcpServerPSProvider.Format.ps1xml
PS_DhcpServerv4Lease_v1.0.0.cdxml
PS_DhcpServerV4Scope_v1.0.0.cdxml
Ive edited DhcpServer.psd1 to remove all functions other than Get-DhcpServerv4Scope and Get-DhcpServerv4Lease, these are the only two i need for this tool.
heres the output of my attempt:
PS /root/itapp> Import-PowershellDataFile ./tools/powershell/DhcpServer.psd1
Name Value
---- -----
TypesToProcess DhcpServerPsProvider.Types.PS1XML
ClrVersion 4.0
NestedModules {PS_DhcpServerv4Lease_v1.0.0.cdxml, PS_DhcpServerV4Scope_v1.0.0.cdxml}
Author Microsoft Corporation
CompanyName Microsoft Corporation
Copyright © Microsoft Corporation. All rights reserved.
FunctionsToExport {Get-DhcpServerv4Scope, Get-DhcpServerv4Lease}
FormatsToProcess DhcpServerPsProvider.Format.ps1xml
HelpInfoUri http://go.microsoft.com/fwlink/?linkid=285742
GUID 90eaa9df-133a-450c-8728-91055cd946a1
ModuleVersion 2.0.0.0
PowerShellVersion 3.0
PS /root/itapp> Get-DhcpServerv4Scope -ComputerName 10.66.56.66
Get-DhcpServerv4Scope : The term 'Get-DhcpServerv4Scope' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-DhcpServerv4Scope -ComputerName 10.10.10.10
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-DhcpServerv4Scope:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS /root/itapp>
can anyone help me out?
Thanks
The .psd1 file is the Module Manifest file. There should also be a .psm1 file that contains the code (unless it's a compiled module).
To load the module you need to use:
Import-Module ./tools/powershell/DhcpServer.psd1
The Import-PowershellDataFile just reads the contents of the datafile in to a hashtable, it doesn't load the functions/cmdlets.
Related
After the recent Windows 10 update my powershell scripts that use the cloudberry snapin are no longer working. I've re-installed cloudberry already with no success.
Even though the snapin is showing as registered:
PS C:\> Get-PSsnapin -Registered
Name : CloudBerryLab.Explorer.PSSnapIn
PSVersion : 2.0
Description : CloudBerry Explorer snap-in for PowerShell
Powershell can't recognize the command:
PS C:\> $destination = Get-CloudFilesystemConnection | Select-CloudFolder
"\\diskstation\drive1\backups\ow-data\"
Get-CloudFilesystemConnection : The term 'Get-CloudFilesystemConnection' is
not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the
path is correct and try again.
At line:1 char:16
+ $destination = Get-CloudFilesystemConnection | Select-CloudFolder "\\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-
CloudFilesystemConnection:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The snapin is also being added to the current session but still doesn't show:
PS C:\> Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn
PS C:\> Get-PSsnapin
Name : Microsoft.PowerShell.Core
PSVersion : 5.1.17134.81
Description : This Windows PowerShell snap-in contains cmdlets used to
manage components of Windows PowerShell.
Ended up doing a re-pave (via "reset") to Win10 and spent the day reinstalling apps. The first app to install after the reset was Cloudberry and the plugin worked fine. The O/S was admittedly a bit old in the teeth having been upgraded from 7 a couple years ago. Thanks for your help attempts.
On a Windows 7 Professional system, it seems not possible to run New-SelfSignedCertificate. I could on a Windows 10 system.
Yes, the shell was started with "Run As Administrator."
PS C:\> new-selfsignedcertificate
new-selfsignedcertificate : The term 'new-selfsignedcertificate' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
+ new-selfsignedcertificate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (new-selfsignedcertificate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10586 117
As stated in the comments above, this isn't available in Windows 7.
However, if you're looking for something with a similar API and capability, then I have used & can recommend this from Microsoft Script Centre:
https://gallery.technet.microsoft.com/scriptcenter/self-signed-certificate-5920a7c6
Have to install AzureRM module to use azure commands through powershell. You can use below command to do it.
Install-Module -Name AzureRM -AllowClobber
I have installed Powershell in my Ubuntu machine. When I enter Login-AzureRmAccount into PowerShell, I get error as below:
PS> Login-AzureRmAccount
Login-AzureRmAccount : The term 'Login-AzureRmAccount' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Login-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Login-AzureRmAccount:String) [], CommandNotFoundException
When I enter Get-Module -ListAvailable -Name Azure -Refresh, I didn't get any result.
PowerShell version:
powershell -version
powershell v6.0.0-alpha.17
How to solve the above error?
You need to install the Azure PowerShell module first:
#Azure RM NetCore Preview Module Install
powershell Install-Module AzureRM.NetCore.Preview
powershell Import-Module AzureRM.NetCore.Preview
This is my test.
root#shui:/home# powershell
PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS /home> Login-AzureRmAccount
VERBOSE: To sign in, use a web browser to open the page https://aka.ms/devicelogin and enter the code F2RKUXRNE to authenticate.
For more information please refer to this link.
It appears that PowerShell 2.0 cannot handle a space in the Env:PSModulePath variable when looking for a module. I have the function in a .psm1 file in a directory under the "\ORGHOST\USRSHR\USERS\lit\My Documents\WindowsPowerShell\Modules" directory.
My organization requires that my Windows document directory be on a network share. This causes the $Env:PSModulePath variable to have "My Documents" as part of the path in the first entry. No, I cannot change the policies set by the organization.
It sounds like I should iterate over the paths in $Env:PSModulePath and find the short (8.3) name for each, then set $Env:PSModulePath using those in my profile script. I would welcome a better suggestion. Any ideas?
If anyone could confirm that this is a problem in PowerShell 2.0, that would be helpful in pushing the organization to upgrade to PowerShell 5.0.
PS 5.0
PS C:\src\powershell> $Env:PSModulePath -split ";"
\\ORGHOST\ORGSHR\Users\lit\My Documents\WindowsPowerShell
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PS 2.0
PS C:\Users\lit> $Env:PSModulePath -split ";"
\\ORGHOST\ORGSHR\USERS\lit\My Documents\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
The term 'Phs-RunBat' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At \\ORGHOST\USRSHR\Users\lit\Scripts\PSAutomation\Phs-RunRemoteBat.ps1:17 char:23
+ [int32]$r = Phs-RunBat <<<< -ComputerName $ComputerName -ScriptPath $ScriptPath -LogFile $LogFile -Verbose
+ CategoryInfo : ObjectNotFound: (Phs-RunBat:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Creating and running an alias in a current Powershell session works,
Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.
PS C:\Windows\system32> new-item alias:eadt -value "C:\adt-bundle-windows-x86_64-20140702\eclipse\eclipse.exe"
CommandType Name ModuleName
----------- ---- ----------
Alias eadt -> eclipse.exe
PS C:\Windows\system32> eadt
but fails in a new session:
PS C:\Windows\system32> eadt
eadt : The term 'eadt' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ eadt
+ ~~~~
+ CategoryInfo : ObjectNotFound: (eadt:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\system32>
You should save your alias in your profile (like in .bashrc in Linux). Hava a look to About_profile to choose your one.
$Profile var gives you the path to your profile file.
It exists 4 different profil files given by :
$profile.AllUsersAllHosts
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
$profile.AllUsersCurrentHost
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
$profile.CurrentUserAllHosts
C:\Users\JPB\Documents\WindowsPowerShell\profile.ps1
$profile.CurrentUserCurrentHost
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1