Power shell: Import-Module - c#

I have been trying to us the app fabric caching on a win2008 standard server. When I execute the follwowing command I get:
Import-Module DistributedCacheAdministration
Import-Module : The specified module 'DistributedCacheAdministration' was not loaded because no valid module file was found in any module directory.
Where is this directory located and how can I use that module
Also, it appears that I have powershell 1. I cant seem to install powershell 2

Modules and their commands is a feature in Powershell 2 only, so you can be quite certain you're running this version. I guess you're confused because the Powershell.exe is located in a "1.0" directory; that's only to make version 2.0 backwards compatible.
You need to specify the exact location of the module to load: Import-Module [-Force] path-to-module-file`
Even better is have it available via the $PSModulePath environment variable. Try a Get-Module -ListAvailable to see what modules are available. Since the one you're trying to load does not seem to be listed, try setting the $PSModulePath to the folder above the directory holding the module file.
When you're satisfied with having the correct module path, set it via Computer Properties.

I installed AppFabric and the folder shows up at C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DistributedCacheAdministration
Yet Import-Module DistributedCacheAdministration doesn't work and the module isn't listed in Get-Module -ListAvailable

Related

C# cmdlet dll that references other project dll fails on load

I have a C# project used as PowerShell cmdlet - this should be the API to the main function of a product - so I have to reference a lot of dll's in my PowerShell library.
My problem is that customers want to load the PowerShell dll from any location without settings the working directory to the program folder where all dll's are located. But I only can use my PowerShell commands if I open Powershell by a shortcut where the working dir is set to the program files folder like this:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noexit -command "[reflection.assembly]::loadFrom('.\PSAPI.dll') | import-module"
and set also the working dir to my program files folder where the product is already installed.
If I just use
[Reflection.Assembly]::LoadFile("C:\Program Files(x86)\MyProduct\PSAPI.dll")
or
[Reflection.Assembly]::LoadFrom("C:\Program Files(x86)\MyProduct\PSAPI.dll")
it always fails. Is there a solution for that (without copying all files to PowerShell folder)?
Here is what I try and the error I get - I can't set the referenced dll's in other way - the .NET application is looking in the working dir for referenced dll's - I set the working dir in powershell to ensure I'm in the right directory, but it won't load my module
[reflection.assembly]::loadFrom( 'C:\Program Files (x86)\ASG-Remoteesktop 2016\ASGRD-PSAPI.dll' ) | import-module
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or
assembly 'file:///C:\Program Files (x86)\ASG-Remoteesktop
2016\ASGRD-PSAPI.dll' or one of its dependencies. The system cannot find the
file specified."
At line:1 char:1
+ [reflection.assembly]::loadFrom( 'C:\Program Files (x86)\ASG-Remoteesktop
2016\A ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
Guessing here as you haven't provided the error but if it works from the same directory and not from another, it's probably that the C# DLL uses relative paths.
When the current directory is C:\Program Files(x86)\MyProduct it doesn't matter if you use the full path or just Resources\MyFile.dat, both will end up at the same place. However if you are in root C: the relative path will look for C:\Resources\MyFile.dat which of course doesn't exist. When you use C:\Program Files(x86)\MyProduct\Resources\MyFile.dat it doesn't matter what the current directory is, it will always work.
Check your C# DLL for any relative paths and either temporarily change the working directory or use absolute paths instead.
One approach could be: add your assembly path C:\Program Files(x86)\MyProduct to PSModulePath environment variable. Once that is done, you can execute import-module -name <name of your module> and it will load it from your folder. In that case you won't need to load your assembly explicitly (most probably).
For more details execute following command in powershell and check the details given for -name parameter.
get-help import-module -detailed

Adding C# support to SCons on Mac

I found C# support for SCons (https://bitbucket.org/russel/scons_csharp/overview), but I don't know where to install (copy) the python scripts are copied into.
I installed Scons with brew command, so I have /usr/local/Cellar/scons/2.3.4 directory on my Mac.
What should be the next step to install the C# builders?
Please visit the index of all external SCons Tools at http://www.scons.org/wiki/ToolsIndex . Under the section "Install and usage" you can find a list of search directories for each platform.
Note that, since the C# support is not a core package, it's not installed into your default SCons distribution. Instead, it's treated like a customization (decoration?) of the standard sources...hence the machine/user-specific search paths.
Create a directory ~/.scons/site_scons/site_tools.
cd ~/.scons/site_scons/site_tools
hg clone https://bitbucket.org/russel/scons_csharp
Change one line (460) from csharp.py (~/.scons/site_scons/site_tools/scons_csharp/csharp.py).
env['CSC'] = env.Detect('mcs') or 'csc'
We need this change because the default setting for compiler (gmcs) is outdated.
Create build file: SConstruct.
env = Environment(
tools=['scons_csharp']
)
sources = ['Hello.cs']
prog = env.CLIProgram('myapp', sources)
Execute scons -Q to get:
mcs -nologo -noconfig -out:.../myapp.exe Hello.cs
References
http://www.scons.org/wiki/ToolsIndex
http://www.scons.org/wiki/CsharpBuilder

Powershell v4 not importing module automatically

I am using Microsoft PowerShell v4:
PS C:\> get-host
Name : ConsoleHost
Version : 4.0
InstanceId : 3b4b6b8d-70ec-46dd-942a-bfecf5fb6f31
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : de-CH
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
I have developed a C# project in Visual Studio 2012 targeting .NET Framework 4 which contains some Cmdlet and the Snapin. I can debug them and everything works just fine.
I've created the path C:\PowerShell\Modules\ and added it to the PSModulePath environment variable.
I put the rMySnapIn.dll to the path C:\PowerShell\Modules\MySnapIn.
I would expect that the module is automatically loaded so I have my new cmdlets ready to use, but they're not: the module is not loaded. I have to write Import-Module MySnapin in order to get it loaded.
How can I get the module automatically loaded?
A checklist that may help you identify the issue:
According to What's New in Windows PowerShell, "Automatic importing of modules is triggered by (a) using the cmdlet in a command, (b) running Get-Command for a cmdlet without wildcards, or (C) running Get-Help for a cmdlet without wildcards." (That applies to V3 and V4.) How did you confirm the module was not loaded?
According to about_Modules, "Only modules that are stored in the location specified by the PSModulePath environment variable are automatically imported." You stated that you did add your path to PSModulePath. When I examine mine, I see that each path included is terminated with a backslash, so in your case you would need C:\PowerShell\Modules\ rather than just C:\PowerShell\Modules. What is the value of your $env:PsModulePath ?
According to this post from Thomas Lee as well as my own experience, autoloading does not work with script modules; however, you state you are using a compiled module, so this should not be your issue.
The $PSModuleAutoLoadingPreference preference variable can be used to turn off autoloading; however, unless you have explicitly changed it, it defaults to All so likely that is not the problem (about_Preference_Variables shows you the possible values). What is your value of $PSModuleAutoLoadingPreference ?
Last but not least--I am particularly suspicious over the fact that you seem to be mixing snapins and modules. They are distinct types of entities, and are not designed to be mixed. Snapins are loaded via Add-PSSnapin. Modules are loaded via Import-Module. And modules, as you know, are also loaded by auto-loading--I suspect that may not be true of code written as a snapin. Furthermore, snapins are deprecated; new code should be written using modules (that is, derive from Cmdlet or PSCmdlet, as detailed in Writing a Windows PowerShell Cmdlet).
If you want to load it automatically you can add the Import-Module MySnapin command line to your PowerShell profile.
To find out the location of your PowerShell profile just type $profile in a PowerShell and by default the profile path is:
C:\Documents and Settings\User\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
If the Microsoft.PowerShell_profile.ps1 file does not exist just create it.
I noticed that following structure is not supported by PowerShell 4:
Modules\MySnapIn\1.0.0\MySnapIn.psm1
Works fine after update to version 5.
Note: I'm authoring only script modules, so I may be wrong.
PowerShell module autoload depends on command discovery. I suspect that if you create manifest (New-ModuleManifest) and name commands that your binary module exposes, autoloading should kick-in and load module if someone will try to use one of these commands:
New-ModuleManifest -Path MySnappin.psd1 -RootModule MySnappin.dll -CmdletsToExport Get-Foo, Set-Bar

How do I correctly install the Facebook SDK Unity plugin?

My current process is approximatly:
I start with a Disk image of Window 7 x64 with only:
Unity 4.3.3f1, Located 'C:\Program Files(x86)\Unity'.
The adt-bundle-windows-x86-20131030. 'C:\Users\Will\adt...'.
The Java 32bit runtime 1.7.0_51-b13, 'C:\Program Files(x86)\Java'.
'C:\Program Files(x86)\Java\jr7\bin;' is manually added to my 'Path' Environment Varible.
As it is I can cleanly deploy Android projects, however I want to use the official Facebook SDK plugin. At this point on my first attempt to install the plugin I dropped it into a project as per the official 'Getting Started' tutorial and this is where I get a bit lost. Even though there is no mention of it in the 'Getting Started' tutorial I find that OpenSSL is a dependancy of the SDK.
So I install the OpenSSL binary 'Win32OpenSSL-1_0_1f' to 'C:\Program Files(x86)\OpenSSL-Win32' and when the plugin still can't find it I add 'C:\Program Files(x86)\OpenSSL-Win32\bin;' to my 'Path' Environment Variable.
At this point The plugin's 'Debug Key Hash' starts working and I naievly assume that everything is correct, However; When I attempt to deploy a build I recieve the following error:
Error building Player: Win32Exception: ApplicationName='C:\Program Files (x86)\Java\jre7\bin\javac.exe', CommandLine='-bootclasspath "C:/Users/Will/adt-bundle-windows-x86-20131030/adt-bundle-windows-x86-20131030/sdk/platforms/android-19\android.jar" -d "C:\Users\Will\Documents\Unity Projects\test\Temp\StagingArea\bin\classes" -source 1.6 -target 1.6 -encoding ascii "com\DefaultCompany\test\R.java" "com\facebook\android\R.java"', CurrentDirectory='C:\Users\Will\Documents\Unity Projects\test\Temp\StagingArea\gen'
and the build process is halted.
Could anyone help explain where I am going wrong and to get this plugin to behave?
I had the exact same issue - I've solved it by deleting the JAVA_HOME environment variable that pointed to a directory containing JRE (instead of JDK). You also seem to only have JRE installed and the javac.exe file is not part of that package. Alternatively, point JAVA_HOME to the directory on your machine that does have JDK (and javac.exe) installed.

Enable - SP Feature fails to find the configuration section in the web apps config

I have a site for which i want to activate feature using powershell
When i run the following command :
enable-spfeature FEATURE NAME -url http://URL
it throws an error :value cannot be null parameter name section.
it basically fails to find the configuration section located under the web application configuration.If i create a file with name powershell.exe.config and place it under the
powershell folder ,it works fine but i dont want to touch the system folder.
Is it possible to give powershell a path of config located int some other folder and ask it to use that while activating feature.
I have tried something like this but with no luck
$configpath = "C:\DevTools.exe.config"
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$configpath)
enable-spfeature Feature name -url http://url
Why arn't you putting the configuration information in the web application web.config file?
#Lee Activating the feature from powershell expects the configuration to be under the hosting process which is powershell in this case.
The solution to my problem was to load the configuration at run time as shown below and using windows powershell instead of using sharepoint management shell :
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$configpath)
add-type -path C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Configuration.dll
Add-PSSnapin Microsoft.Sharepoint.PowerShell
enable-spfeature $FeatureName -url http:\\url

Categories