powershell-remoting

How to get DatabaseCopies from MailboxDatabase programmatically in C# (wrapped ExchangeMangementShell cmdlets in c#)?

烂漫一生 提交于 2020-01-06 11:01:17
问题 I am wrapping ExchangeManagementShell Cmdlets in C#, to programmatically execute cmdlets (Please refer to __http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/155504b3-ffe3-4bdf-887a-1e61842a8697) I know the "databasecopies" property of mailboxdatabase contains copies. But i am not sure how to parse the deserilzied databasecopies data to get the properites. Please see the below code snippet. I am basically parsing Get-MailboxDatabase cmdlet results to get the

Robocopy commands to copy a file to over 50 remote machines

泪湿孤枕 提交于 2020-01-05 08:13:33
问题 I started looking at robocopy yesterday to try to copy and overwrite a file from one destination to many remote computers. I've tried Robocopy to copy files to a remote machine but it doesn't work. I get the same error as the person in the link. Does anybody have any suggestions or lead me in the right way ? thank you so much ! 回答1: You could just use PowerShell for this. It has an inefficiency issue wherein it would copy one at a time but that shouldnt be an issue for 50ish machines. This

Use Windows Powershell ISE for Exchange when you have MFA

◇◆丶佛笑我妖孽 提交于 2020-01-05 05:33:08
问题 I have been using Windows PowerShell ISE for some time, connecting to Azure AD,Exchange and SharePoint successfully. Recently a change in the organisation was made so we are now using MFA with exchange, I followed this https://technet.microsoft.com/en-us/library/mt775114(v=exchg.160).aspx and everything works as expected. My question is - Is there a way to use windows PowerShell ISE to run exchange commands now? Now it seems I am required to open the Exchange Online Remote PowerShell Module

Functions & powershell remoting

社会主义新天地 提交于 2020-01-03 16:45:09
问题 I have a script that works fine but I want to improve my powershell knowledge and would like to know if there is an easier way to do this..... Part of my script connects to a sever and pulls bak a list of files and sizes on it and exports it to a csv. I have found a function (Exportcsv) that allows me to append to the csv with earlier versions of powershell. At the moment I use the invoke-command to remote to each server and the run the script in the script block but this means adding the

Stripping value in PS and comparing if it is an integer value

倾然丶 夕夏残阳落幕 提交于 2020-01-03 05:50:12
问题 I am running PS cmdlet get-customcmdlet which is generating following output Name FreeSpaceGB ---- ----------- ABC-vol001 1,474.201 I have another variable $var=vol Now, I want to strip out just 001 and want to check if it is an integer. I am using but getting null value $vdetails = get-customcmdlet | split($var)[1] $vnum = $vdetails -replace '.*?(\d+)$','$1' My result should be integer 001 回答1: Assumption: get-customcmdlet is returning a pscustomobject object with a property Name that is of

PowerShell ScriptBlock and multiple functions

非 Y 不嫁゛ 提交于 2020-01-02 12:45:55
问题 I have written the following code: cls function GetFoo() { function GetBar() { $bar = "bar" $bar } $foo = "foo" $bar = GetBar $foo $bar } $cred = Get-Credential "firmwide\srabhi_adm" $result = Invoke-Command -Credential $cred -ComputerName localhost -ScriptBlock ${function:GetFoo} Write-Host $result[0] Write-Host $result[1] It works but I don't want to define GetBar inside of GetFoo . Can I do something like this? cls function GetBar() { $bar = "bar" $bar } function GetFoo() { $foo = "foo"

Azure Custom Script Extension. Execute script as another user

走远了吗. 提交于 2019-12-31 02:41:52
问题 I'm using command1.ps1 script to install Azure Custom Script Extension on the target VM and execute command2.ps1. command2.ps1 is supposed to run a script (that is inside ScriptBlock) as domain administrator (hence -Credential $Credentials ). When I run command2.ps1 manually and input $domainAdminName and $domainAdminPassword it works, but when running it through command1.ps1 it doesn't work. Maybe the problem is cause by Azure Custom Script Extension running command2.ps1 as System account?

Does powershell remoting support version of the powershell to be used on remote target?

徘徊边缘 提交于 2019-12-29 08:25:09
问题 Can I supply a version of powershell to be used on the target machine while ps remoting. May be my question is not proper or not possible to answer but if any body having idea please help me. I am trying to do a remoting using powershell on a machine where powershell 2.0 3.0 and 4.0 versions are available , but I want to use the version 4.0 only (on target machine) is it possible? Thanks Gyan 回答1: Yes, there is a way to connect to a specific version of Powershell on a remote machine. It does

To call a powershell script file (example.ps1) from C#

随声附和 提交于 2019-12-28 15:58:31
问题 I tried running a script localwindows.ps1 from C# using the following Code : PSCredential credential = new PSCredential(userName, securePassword); WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "machineName", 5985, "/wsman", shellUri, credential); using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo)) { runspace.Open(); String file = "C:\\localwindows.ps1"; Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(file); pipeline

PowerShell Remoting $Using variable scope

倖福魔咒の 提交于 2019-12-28 04:15:07
问题 I have folder c:\test where I have three files: “file1”, “file2”, “file3” Following script: $remoteSession = New-PSSession -ComputerName localhost $folder = "c:\test" $exclude =@("c:\test\file1","c:\test\file2") Invoke-Command -Session $remoteSession -ScriptBlock { #$Using:exclude Get-ChildItem -Path $Using:folder -recurse | Where {$Using:exclude -notcontains $_.FullName} } Remove-PSSession $remoteSession Gives the result: However, if I uncomment “$Using:exclude” I get the result: Suddenly