Hi
I am trying to create a script there reading servers diskspace.
I have run the script from a client to the domain server.
Here is a part of the script;
The problem is, I have got access denied
The function of the right is…
function Set-Rättigheter{ #Param tillater å sende argumenter til funksjonen param( [Parameter(Mandatory=$false)] $ip ) $sjekk = $false $KollaDomain = $false Set-ExecutionPolicy Unrestricted -Force #Hvis funksjonen har mottatt argument til ip variabelen skal en ikke gå inn i if-setning så lenge sjekk er usann. if($ip -eq $null){ $ip = Read-Host "Skriv in ip adressen till domänen kontrollanten" # Ger Trust $DCServer =[System.Net.Dns]::GetHostEntry($ip).Hostname set-item wsman:\localhost\Client\TrustedHosts -value $DCServer $username = Read-Host "Skriv in ditt Admin konto" $passord = Read-Host "Skriv in passord" -AsSecureString #Oppretter et PSCredential objekt $Global:tilgang = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$passord $KollaDomain = $true } #Oppretter en ny powershell sesjon til en ekstern maskin $Global:s = New-PSSession -ComputerName $ip -Credential $tilgang -ErrorVariable err if($KollaDomain -eq $true){ #Henter ut domeneinformasjon $domain = Invoke-Command $s {Get-ADDomain} #Henter ut domenenavnet fra domeneinformasjonen $domain = $domain.name #Legger domenenavnet sammen med brukernavn. $username = $domain + "\" + $username #Oppretter innloging informasjon til domenet $Global:tilgang = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$passord } #Utskrift hvis ikke maskin kan kontaktes if($err[0]-ne $null){ Write-Host "Fikk ikke kontakt med ekstern maskin" } return $ip }
and the error message is …
New-PSSession : [192.xxx.xxx.xxx] Connecting to remote server 192.xxx.xxx.xxx failed with
the following error message : The WinRM client cannot process the request. Default aut
hentication may be used with an IP address under the following conditions: the transpo
rt is HTTPS or the destination is in the TrustedHosts list, and explicit credentials a
re provided. Use winrm.cmd to configure TrustedHosts. Note that computers in the Trust
edHosts list might not be authenticated. For more information on how to set TrustedHos
ts run the following command: winrm help config. For more information, see the about_R
emote_Troubleshooting Help topic.
At C:\Scripts\statistik.ps1:40 char:21
- … $Global:s = New-PSSession -ComputerName $ip -Credential $tilgang -Err …
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:RemoteRun
space) [New-PSSession], PSRemotingTransportException - FullyQualifiedErrorId : CannotUseIPAddress,PSSessionOpenFailed
Invoke-Command : Cannot validate argument on parameter ‘ScriptBlock’. The argument is
null. Provide a valid value for the argument, and then try running the command again.
At C:\Scripts\statistik.ps1:44 char:38
- CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:RemoteRun
-
$domain = Invoke-Command $s {Get-ADDomain}
-
~~
- CategoryInfo : InvalidData: ( [Invoke-Command], ParameterBindingVali
dationException - FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.C
ommands.InvokeCommandCommand
- CategoryInfo : InvalidData: ( [Invoke-Command], ParameterBindingVali