powershell-remoting

Difference between Invoke-Command and query directly

强颜欢笑 提交于 2019-12-11 14:25:12
问题 I'm currently working on a script that queries the disk information from a server. I'm stack with a problem and I really don't know whats going on here. May you can help me. The following code is working (ComputerName replaced): $space1 = Invoke-Command -ComputerName "xxxxxx" -ScriptBlock { Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='C:'" } This code works kinda well and may takes around 2 seconds to execute. After some experimenting I found a way how I can query it even faster.

Powershell tasks from local machine to remote machine

岁酱吖の 提交于 2019-12-11 13:59:08
问题 I am performing below tasks on remote machine from a local machine: Creating/Deleting/Modifying some directory Copying some folder from local to remote machine Installing some .exe silently with noninteractive option Exectuing some batch files I want to write a script in PowerShell. Novice to PowerShell. I have done some basic investigation of terms like "PowerShell Remoting" etc. What are the things I need to look for? Related exmple for this will help, where should I look for those? 回答1:

Unable to fetch application pools from list of remote servers. Looping isnt working

强颜欢笑 提交于 2019-12-11 11:51:04
问题 Can someone please help me on this.!? Following is the ps script that i am working with to fetch application pool details from a remote machine. It works when tried on the same machine or when the script is executed line by line. It isnt working when it is executed as a script file. Then it shows the application pool details of the server from which the script is running throughout its output. The echo is showing hostnames and its looping correctly. But i am not sure why the script isnt

Remote command failure even after unencrypted traffic is true

回眸只為那壹抹淺笑 提交于 2019-12-11 11:41:54
问题 I am trying to open remote PSSession from one PC to another. Both PCs are in the LAN and reachable, but whenever I try to enter PSSession the following error occurs: Enter-PSSession : Connecting to remote server pc2 failed with the following error message : The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration. Change the client configuration and try the request again. For more information, see the about_Remote_Troubleshooting Help

Powershell ScriptBlock Not Executing

可紊 提交于 2019-12-11 05:47:06
问题 I'm trying to execute code on a remote machine using invoke-command . Part of that method includes a ScriptBlock parameter, and I get the sense that I'm not doing something correctly. First I tried to create a method in the script, which looked like this: param([string] $filename) function ValidatePath( $file, $fileType = "container" ) { $fileExist = $null if( -not (test-path $file -PathType $fileType) ) { throw "The path $file does not exist!" $fileExist = false } else { echo $filename found

Unable to query [adsisearcher] for trusted domains (PowerShell)

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:04:48
问题 I wanted to query [adsisearcher] to get me the OU info for a few servers for servers in trusted & non trusted domains. $session = New-PSSession -ComputerName icvmm02 Invoke-Command -Session $session -ScriptBlock { $compname= (Get-WmiObject "Win32_Computersystem" -namespace "root\CIMV2" -computername $comp).name $searcher = [adsisearcher]"(&(ObjectCategory=computer)(Name=$compname))" $ou= $searcher.FindOne() | Select-Object path $serverou = $ou.path } $adou= (Invoke-Command -Session $session

Catch RPC Server Unavailable Error HRESULT: 0x800706BA

放肆的年华 提交于 2019-12-10 19:05:39
问题 In powershell, I can catch Access is Denied error using Catch [System.UnauthorizedAccessException]. How do I similarly catch RPC Server Unavailable error? 回答1: If you add the common parameter -ErrorAction Stop to the, in my case, get-wmiobject command it will cause the command to respond to this non-terminating error as a terminating error and drop it to catch for action. Here is the code I'm using for this purpose. I probably should be more specific in the catch, but it works for now. # Is

“Access denied” on Remote winrm [closed]

陌路散爱 提交于 2019-12-10 03:22:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I created a Windows VM on Windows Azure with winrm over SSL set. But, I can't connect it using a powershell script. When I'm running the following: ​Enter-PSSession -ConnectionUri https://myniceapp.cloudapp.net:5986 -Credential "hostname/username" -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) I

Creating Local User on Remote Windows Server and Add to Administrator Group

喜你入骨 提交于 2019-12-08 07:02:32
问题 I have Created PowerShell script to create User on remote Windows Server and add to Administrator group: $Computer = Read-Host "Computer name:" $UserName = Read-Host "User name:" $Password = Read-Host "Password" -AsSecureString $AdminGroup = [ADSI]"WinNT://$Computer/Administrator,group" $User = [ADSI]"WinNT://$Computer/$UserName,user" $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, (ConvertTo-SecureString $Password -AsPlainText –Force) $User

Creating Local User on Remote Windows Server and Add to Administrator Group

久未见 提交于 2019-12-08 03:20:29
I have Created PowerShell script to create User on remote Windows Server and add to Administrator group: $Computer = Read-Host "Computer name:" $UserName = Read-Host "User name:" $Password = Read-Host "Password" -AsSecureString $AdminGroup = [ADSI]"WinNT://$Computer/Administrator,group" $User = [ADSI]"WinNT://$Computer/$UserName,user" $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, (ConvertTo-SecureString $Password -AsPlainText –Force) $User.SetPassword($Cred.GetNetworkCredential().Password) $AdminGroup.Add($User.Path) And It gives me below error