Share via


Use the AllowClober parameter

Question

Wednesday, June 8, 2011 5:11 PM

Hi!

Why this is happening now and never had problems before? what is the solution in order to import my session? use the "AllowClober" where?

Import-PSSession : No command proxies have been created, because all of the requested remote commands would shadow existing local commands. Use the AllowClober parameter if you want to shadow existing local commands.

MVP Office Development, MCP, MCTS SharePoint 2010 Development

All replies (8)

Wednesday, June 8, 2011 6:26 PM

Greetings Joao!

I'm not sure I understand your question.  What session are you trying to import and to where?

Vickie


Thursday, June 9, 2011 10:38 AM

Hi, thanks 4 helping, so this is the point.

I am using the PowerShell Outlook Live ToolKit http://archive.msdn.microsoft.com/psoutlooklive/Release/ProjectReleases.aspx?ReleaseId=4513, but i don't know if there where any changes in the PowerShell Server for https://ps.outlook.com/powershell/ because i cannot create my session from C# anymore.

I tried to create and import my session from the PowerShell CMD, but when importing the error was fired.

So the problem is in the "var result" that return always ZERO

 

var command = new PSCommand();
      command.AddScript(string.Format(SessionScripts.NewSessionScript, connectionUri));
      var result = this.runspace.ExecuteCommand<PSSession>(command);
      return result[0];

MVP Office Development, MCP, MCTS SharePoint 2010 Development


Thursday, June 9, 2011 11:09 AM

UPDATE

I created the methods directly but no matter the URI i put there it simply do no connect to PowerShell, strange, always worked .. any update?

public static void xx()
    {
      // Below namespaces should be imported for PowerShell.
      // These are available from System.Management.Automation.dll
      // System.Management.Automation.dll is installed as part of Windows
      // Management Framework installation.

      // Create Runspace and remote session to Oulook Live which is imported to
      // this RunSpace.
      Runspace runspace = RunspaceFactory.CreateRunspace();
      runspace.Open();

      // Set credentials to make a remote connection to Outlook Live
      string userName = "[email protected]";
      string password = "Paxxxxxx";

      SecureString secureString = new SecureString();
      foreach (char c in password) secureString.AppendChar(c);

      PSCredential cred = new PSCredential(userName, secureString);
      // Script to set a variable. This variable is used by new session script.
      string setVariableScript = "Set-Variable";
      PowerShell ps1 = PowerShell.Create();
      PSCommand setVariableCommand = new PSCommand();
      setVariableCommand.AddScript(setVariableScript);
      setVariableCommand.AddParameter("Name", "Cred");
      setVariableCommand.AddParameter("Value", cred);
      ps1.Commands = setVariableCommand;
      ps1.Runspace = runspace;
      ps1.Invoke<PSObject>();

      // Create a remote session to Outlook Live
      // Script to create a new session 
      string newSessionScript = "New-PSSession -ConfigurationName:Microsoft.Exchange -Authentication:Basic -ConnectionUri:{0} -Credential $Cred -AllowRedirection";
      // Outlook Live endpoint for PowerShell connection
      string connectionUri = "https://pod51007psh.outlook.com/PowerShell-LiveID?PSVersion=2.0";
      PowerShell ps2 = PowerShell.Create();
      PSCommand createCommand = new PSCommand();
      createCommand.AddScript(string.Format(newSessionScript, connectionUri));
      ps2.Commands = createCommand;
      ps2.Runspace = runspace;
      PSSession session = ps2.Invoke<PSSession>()[0];
      // Import the remote session into Runspace
      // Script to import a new session
      string importSessionScript = "Import-PSSession";
      PowerShell ps3 = PowerShell.Create();
      PSCommand importCommand = new PSCommand();
      importCommand.AddCommand(importSessionScript);
      importCommand.AddParameter("Session", session);
      ps3.Commands = importCommand;
      ps3.Runspace = runspace;
      ps3.Invoke<PSObject>();
    }

MVP Office Development, MCP, MCTS SharePoint 2010 Development


Friday, June 10, 2011 1:43 AM

Greetings Joao!

I'm not able to help you with scripting as it does not really apply to Online Service in this context.  I will leave this thread open in efforts to have your peers answer your question for you.

Vickie


Saturday, June 11, 2011 11:24 AM

Joao,

This coding is beyond my experties, but could you be maxing out your PS Sessions? I do some basic scripting and if I open/close PS sessions frequently in a day eventually I am unable to establish the PS Session. You could check that.

Jorge R. Diaz, PMP, CCNA, MCSA, MCSE, MCTS

Senior Microsoft Consultant

Planet Technologies, Inc.

Check out My Blog!


Monday, June 20, 2011 9:36 AM

Hi!

I don't think so because i can connect within the PS Console, simply from one day to another the code stop work, bellow my console log

PS C:\Users\malves> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com
/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
WARNING: Your connection has been redirected to the following URI:
"https://pod51007psh.outlook.com/PowerShell-LiveID?PSVersion=2.0 "
WARNING: Your connection has been redirected to the following URI:
"https://amsprd0202psh.outlook.com/PowerShell-LiveID?PSVersion=2.0 "
PS C:\Users\xxxx> Import-PSSession $Session

ModuleType Name           ExportedCommands
            
Script   tmp_2444d435-6712-4d01... {New-SyncMailbox, Set-MailboxAutoReplyConfiguration, Set-PopSubscription...

MVP Office Development, MCP, MCTS SharePoint 2010 Development


Tuesday, July 5, 2011 8:02 AM

I facing the same problem, my prototype C# code worked a few weeks ago without any problems.

Nothing has changed but the session's aren't imported anymore! And also in the normal Powershell prompt it still works.

Do you have a update?


Tuesday, July 5, 2011 10:32 AM

Hi!

Yes i have, you must run your APP with a user that can access PowerShell, try to test with the account that you are logged on.

MVP Office Development, MCP, MCTS SharePoint 2010 Development