Hi Scripting guru’s
I just completed Microsoft MVA “Getting started with Microsoft Powershell” in other words I’m totally green to Powershell scripting.
I want to make the script start a remote session to listed serveres in the $servers list, restart all services starting with “MicrosoftDynamicsNavServer$NAS”. When its complete it will look in the eventlog under application for instance ID 214 and write the 10 newest events to a HTM-fil and copy it to an IIS. It restart the services and create the HTM-file but I’m not able to copy the index.htm file to a webserver.
I get error’s like access denied and try without Credential. If I try to run Copy-Item C:\temp\index.htm -destination \WebServer\NAV$ on my local machine i works fine.
$cred = Get-Credential
$Servers = 'NAV-Serv01', 'NAV-Serv02'
$WebServer = 'WebServer'
$Session = New-PSSession -ComputerName $Servers -Credential $cred -Name $Servers
$WebServerSession = New-PSSession -ComputerName $WebServer -Credential $cred
icm -Session $Session {Restart-Service 'MicrosoftDynamicsNavServer$NAS*'}
icm -Session $Session {Get-EventLog -LogName Application -InstanceId 214 -Newest 10 -Verbose | ConvertTo-Html -As Table | Out-File C:\temp\index.htm}
#Copy-Item -Path C:\temp\index.htm -Destination \\webserver\inetpub\wwwroot\NAV
Copy-Item -Path C:\temp\index.htm -Destination C:\inetpub\wwwroot\NAV -ToSession $WebServer