Powershell issues with Start-Transcript - windows

I am trying to log my simple script for windows updates. When I to the Start-Transcript command it starts but it ends right after it starts. Currently running powershell 5.1 below is the code I am trying to log.
#Start Log
Start-Transcript -Path $logFolder\windowsupdate.$logDate.log
#Get and install Windows Updates
Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot
Get-WUInstall -MicrosoftUpdate -AcceptAll -Install -IgnoreReboot
#Set install from MS
#Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d
#stop Logging
Stop-Transcript
The output is below. I started out some information. Also as you can see the start time and end time are the same but the script was still running when it ended the Transcript.
**********************
Windows PowerShell transcript start
Start time: 20190918224703
Username: ********
RunAs User: ********
Machine: ******** (Microsoft Windows NT 10.0.14393.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 9368
PSVersion: 5.1.14393.3053
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.3053
BuildVersion: 10.0.14393.3053
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\********\WU-Logs\windowsupdate.2019-09-18-22-47.log
**********************
Windows PowerShell transcript end
End time: 20190918224703
**********************

Related

Cannot boot Windows guest in VirtualBox without kernel module error

I'm running Vagrant (1.8.1) + VirtualBox (5.0.12) on Windows 7 and trying to boot up a Windows 7 image (modernIE/w7-ie8). However, I get this error:
---------------------------
VirtualBox - Error In supR3HardenedWinReSpawn
---------------------------
<html><b>NtCreateFile(\Device\VBoxDrvStub) failed: 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND (0 retries) (rc=-101)</b><br/><br/>Make sure the kernel module has been loaded successfully.<br><br><!--EOM-->where: supR3HardenedWinReSpawn
what: 3
VERR_OPEN_FAILED (-101) - File/Device open failed.
Driver is probably stuck stopping/starting. Try 'sc.exe query vboxdrv' to get more information about its state. Rebooting may actually help.</html>
---------------------------
OK
---------------------------
I ran the query command, but the service "is not found".
> sc.exe query vboxdrv
[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
The specified service does not exist as an installed service.
I tried rebooting, too. Nothing.
I am on windows 10 and following steps works for me:
Steps:
Navigate to "C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv"
Right click on "VBoxDrv.inf" file and select Install option
Open the Console as a administrator and run the following command
sc start vboxdrv
There's something wrong with the installation of VirtualBox (I've been seeing reports of this problem as far back as 4.x). The installer registers an incorrect location for the driver SYS file (the ImagePath in this example).
PS> Get-ItemProperty HKLM:\system\currentcontrolset\services\vboxdrv
Type : 1
Start : 3
ErrorControl : 1
ImagePath : \??\C:\Program Files\Oracle\VirtualBox\VBoxDrv.sys
DisplayName : VBox Support Driver
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\system\currentcontrolset\services\vboxdrv
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\system\currentcontrolset\services
PSChildName : vboxdrv
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
The file doesn't exist.
PS> Test-Path (Get-ItemProperty HKLM:\system\currentcontrolset\services\vboxdrv).ImagePath
False
The actual location requires an extra drivers\vboxdrv.
PS> Test-Path 'C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv\VBoxDrv.sys'
True
You can update the registered location.
PS> Set-ItemProperty HKLM:\system\currentcontrolset\services\vboxdrv -Name ImagePath -Value '\??\C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv\VBoxDrv.sys'
And now you can start the driver/service.
> sc.exe start vboxdrv
Try the following code (as administrator):
sc.exe start vboxdrv
I did what Anthony Mastrean suggested but I was still getting some errors:
C:\Vagrant>sc query vboxdrv
SERVICE_NAME: vboxdrv
TYPE : 1 KERNEL_DRIVER
STATE : 1 STOPPED
WIN32_EXIT_CODE : 31 (0x1f)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\Vagrant>sc start vboxdrv
[SC] StartService FAILED 123:
The filename, directory name, or volume label syntax is incorrect.
This thread on superuser gave me the solution:
find C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv\ VBoxDrv.inf
right click and select Install
As already pointed out, there seems to be a file-path issue after upgrades, especially when the VBox was open. The question's keyword was not giving any working results for me here, as I could not even find the directory /xboxdrv/ and even the file VBoxDrv.inf so I changed to missing xboxdrv and I found quick windows_approach here https://stackoverflow.com/a/32077300/5922263. It simply says that head to the program list, right-click Oracle VM VirtualBox and click Repair and this time, ensure it is closed first:
ControlPanel > Programs > Programs and Features > Oracle VM VirtualBox
I hope this helps.
> vboxmanage --version
7.0.6r155176
Fix:
C:\Program Files\Oracle\VirtualBox\drivers\vboxsup\VBoxSup.inf # Right Click to install
> sc.exe query vboxsup
> sc.exe start vboxsup

Remote PowerShell : Error 307

On a Widnows 7 PC, I have an error 307 when I run the Invoke-Command or Enter-PSSession in PowerShell. I have the two computers in the trusted zone. When I run the same command on a Windows 8.1 or Windows Server 2012 R2, I don't have the error and the command works perfectly. The target runs Windows Server 2012 R2.
They both run PowerShell v4.0 (for Widnows 7, I upgraded according to MS : https://www.microsoft.com/en-us/download/details.aspx?id=40855).
For Windows 7 :
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18444
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
PS C:\> Enter-PSSession -ComputerName 127.0.0.1
[...]HTTP error 307[...]
+ Enter-PSSession -ComputerName 127.0.0.1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument : (127.0.0.1:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
For Windows 8.1 or Windows Server 2012 R2 :
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34014
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
PS C:\> Enter-PSSession -ComputerName 127.0.0.1
[127.0.0.1]: PS C:>
Moreover, when I test the connexion with Test-WSMan, I get a HTTP error 12152. And the two machines ping the other.
Have you an idea for a possible solution ?
ps : the exact English message when run Invoke-Command :
[xxxxx] Connecting to remote server srvpwdev01 failed with the following error message : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859023" Machine="xxxxx"><f:Message></f:Message></f:WSManFault> For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (srvpwdev01:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108273,PSSessionStateBroken
I have the number 307 in a French Windows.

Unable to set certificate friendly name through PowerShell (access is denied)

I'm trying to update a (root) certificate's friendly name through PowerShell.
The certificate I'm trying to update is highlighted in the screenshot below (taken from certmgr.msc):
Here's the PowerShell code (largely taken from here):
Set-Location cert:
cd .\CurrentUser\Root
$cert = gci .\02FAF3E291435468607857694DF5E45B68851868
$cert.FriendlyName = "UserTrust CA"
(I've verified the thumbprint with the certificate properties in certmgr.msc to make sure it's the same certificate).
The last line will result in the following error:
Exception setting "FriendlyName": "Access is denied.
"
At line:1 char:7
+ $cert. <<<< FriendlyName = "UserTrust CA"
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
I've tried the following things so far:
Running PowerShell as administrator
Changing the execution policy using: Set-ExecutionPolicy Unrestricted
Other information:
PowerShell version is 2.0 (running on Windows 7 Enterprise x64)
I'm running the x64 version of PS
DEP and UAC are disabled
My account is part of the Administrators group
I'm a complete PowerShell n00b ;-)
PS version output:
$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
You need to update your version of Powershell to 3.0 or 4.0.
See Get-ChildItem for Certificate
I have Powershell 4.0 and I was able to change the FriendlyName without problems. This was visible in certmgr.msc after a restart.
You can download Powershell 4.0 here.
If you are a Powershell beginner it's probably better to use Get-ChildItem instead of gci for improved readability. Also, cd is an alias of Set-Location so it's better to choose one or the other in your script to avoid confusion.

The specified module was not loaded 'PSWindowsUpdate'

Description: I am running/executing powershell from a ruby script (.rb) file
exec "powershell.exe Import-Module PSWindowsUpdate"
I downloaded the PSWindowsUpdate module from "Windows Update PowerShell Module" and copied the files to the following location:
%WINDIR%\System32\WindowsPowerShell\v1.0\Modules
When I run the above I get the following error:
Z:\Desktop>ruby windows_patch.rb
Import-Module : The specified module 'PSWindowsUpdate' was not loaded because
no valid module file was found in any module directory.At line:1 char:1
+ Import-Module PSWindowsUpdate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (PSWindowsUpdate:String) [I
mport-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
ands.ImportModuleCommand
However, when I run this via Powershell it runs fine and dandy.
I'm using:
Windows 7 x64
PowerShell v4
Ruby v2.1.5
The result of exec "powershell.exe ruby -e 'puts $:'" is:
C:/Ruby21/lib/ruby/site_ruby/2.1.0
C:/Ruby21/lib/ruby/site_ruby/2.1.0/i386-msvcrt
C:/Ruby21/lib/ruby/site_ruby
C:/Ruby21/lib/ruby/vendor_ruby/2.1.0
C:/Ruby21/lib/ruby/vendor_ruby/2.1.0/i386-msvcrt
C:/Ruby21/lib/ruby/vendor_ruby
C:/Ruby21/lib/ruby/2.1.0
C:/Ruby21/lib/ruby/2.1.0/i386-mingw32
I ran powershell.exe $env:PSModulePath which gave me:
\vmware-host\Shared Folders\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\M
odules\
I then copied the folder to C:\Program Files (x86)\WindowsPowerShell\Modules
I then got:
Import-Module : The specified module 'PSWindowsUpdate' was not loaded because
no valid module file was found in any module directory.At line:1 char:39
Next, I then ran:
PS C:\Users\Justin.Schuhmann> Set-ExecutionPolicy -Scope LocalMachine
cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: Unrestricted
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
This solved the issue, I don't have a permanent solution yet as this is only temporary. When setting

Azure CustomScriptExtension fails on exit code 1 with Azure Powershell - same works fine with Azure Portal

I’ve been working on automation for Azure VM deployment with the Microsoft CustomScriptExtension for VMs.
https://azure.microsoft.com/blog/2014/04/24/automating-vm-customization-tasks-using-custom-script-extension/
The CustomScriptExtension works great from the Azure portal. I just click on the checkbox to enable it, and specify the powershell script located on the Azure storage container and it will run on the VM after it boots up. It succeeds with exit code of 0.
What I need help on is calling the CustomScriptExtension from command line via the Azure Powershell. I’m using azure-xplat-cli to create an Azure Windows VM from the CLI, and everything works (from VM launch encompassing cloud service creation and role creation, to endpoint creation, endpoint ACL creation, enabling CustomScriptExtension on the VM). When I then try to use Azure Powershell to run CustomScriptExtension it fails.
I followed the directions here:
http://fabriccontroller.net/blog/posts/customizing-your-microsoft-azure-virtual-machines-with-the-new-customscript-extension/
It appears CustomScriptExtension works, the script is downloaded, but it fails with exit code 1.
However, if I run the same script manually on the command line, it succeeds.
I can’t seem to get to the root cause without more verbose error messages.
Thanks in advance,
Jeff
Below are some logs comparing a successful run vs the unsuccessful run via Azure Powershell:
For w99app11 when it was launched from Azure portal page (and CustomScriptExtension works). Logs follow:
PS C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\1.1>
cat .\CustomScriptHandler.log
2015-01-14T20:15:48.4897999Z [Info]: Starting IaaS ScriptHandler Extension v1
2015-01-14T20:15:48.5054217Z [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomS
criptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Microso
ft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T20:15:48.5054217Z [Info]: Installing Handler
2015-01-14T20:15:48.5054217Z [Info]: Handler successfully installed
2015-01-14T20:15:51.6818933Z [Info]: Starting IaaS ScriptHandler Extension
v1
2015-01-14T20:15:51.6818933Z [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomS
criptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Microso
ft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T20:15:51.6818933Z [Info]: Enabling Handler
2015-01-14T20:15:51.6818933Z [Info]: Handler successfully enabled
2015-01-14T20:15:51.7287562Z [Info]: Loading configuration for sequence number 0
2015-01-14T20:15:51.8284233Z [Info]: HandlerSettings = ProtectedSettingsCertThumbprint: , ProtectedSettings: {}, Public Settings: {FileUris: [https://portalv
hdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1?sv=2014-02-14&sr=b&sig=qOObvkYmT1pZS7tdFbMYPBeGryD76fz7tfsl8kiSCV0%3D&st=2015-01-14T20%3A03
%3A54Z&se=2114-12-21T20%3A05%3A54Z&sp=r], CommandToExecute: powershell.exe -ExecutionPolicy Unrestricted -File bootstrap-ansible.ps1 }
2015-01-14T20:15:51.8440422Z [Info]: Downloading files specified in configuration...
2015-01-14T20:15:51.8909155Z [Info]: DownloadFiles: fileUri = "https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1?sv=2014-02
-14&sr=b&sig=qOObvkYmT1pZS7tdFbMYPBeGryD76fz7tfsl8kiSCV0=&st=2015-01-14T20:03:54Z&se=2114-12-21T20:05:54Z&sp=r", baseUri = "https://portalvhdslqdvg9p4yz1f8.blob
.core.windows.net/"
2015-01-14T20:15:52.2971695Z [Info]: Files downloaded. Asynchronously executing command: 'powershell.exe -ExecutionPolicy Unrestricted -File bootstrap-ansibl
e.ps1 '
2015-01-14T20:15:52.3127877Z [Info]: Command execution task started. Awaiting completion...
2015-01-14T20:16:16.6145937Z [Info]: Command execution finished. Command exited with code: 0
When I call CustomScriptExtension from Azure Powershell, the same script fails with exit code 1. Logs follow:
NOTE: the CustomScriptExtension run worked, and the script was downloaded and run, but failed on an error with exit code 1
cd C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\
cat .\CustomScriptHandler.log
2015-01-14T19:16:24.4301817Z [Info]: Starting IaaS ScriptHandler Extension v1
2015-01-14T19:16:24.4301817Z [Info]: HandlerEnvironment = Version: 1, HandlerEnvironment: [LogFolder: "C:\WindowsAzure\ Logs\Plugins\Microsoft.Compute.Custom
ScriptExtension\1.1", ConfigFolder: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\RuntimeSettings", StatusFolder: "C:\Packages\Plugins\Micros
oft.Compute.CustomScriptExtension\1.1\Status", HeartbeatFile: "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.1\Status\HeartBeat.Json"]
2015-01-14T19:16:24.4458090Z [Info]: Enabling Handler
2015-01-14T19:16:24.4458090Z [Info]: Handler successfully enabled
2015-01-14T19:16:24.4458090Z [Info]: Loading configuration for sequence number 2
2015-01-14T19:16:24.4770569Z [Info]: HandlerSettings = ProtectedSettingsCertThumbprint: , ProtectedSettings: {}, Public Settings: {FileUris: [https://portalv
hdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1], CommandToExecute: powershell -ExecutionPolicy Unrestricted -file ./bootstrap-ansible.ps1
}
2015-01-14T19:16:24.4770569Z [Info]: Downloading files specified in configuration...
2015-01-14T19:16:24.5083104Z [Info]: DownloadFiles: fileUri = "https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/scripts/bootstrap-ansible.ps1", baseUri
="https://portalvhdslqdvg9p4yz1f8.blob.core.windows.net/"
2015-01-14T19:16:24.8823100Z [Info]: Files downloaded. Asynchronously executing command: 'powershell -ExecutionPolicy Unrestricted -file ./bootstrap-ansible.
ps1 '
2015-01-14T19:16:24.8979517Z [Info]: Command execution task started. Awaiting completion...
2015-01-14T19:16:29.7456296Z [Error]: Command execution finished. Command exited with code: 1

Resources