Wednesday, November 20, 2019

PS | How to read content of any file inside GuestOS without logging in?

I am doing lot around powershell these day. Let's see one more Challenge given and provided solution.

Basically, this challenge belongs to my last blog. Here I was asked to read the content of a file in a VM without accessing RDP. Sound interesting? isn't it?

#Start here
Connect-VIServer vCenter1
$VM = read-host "Enter VM Name " #here is the target vm name

$Chpass = @"
#below command will read and give output for entire file
(Get-Content -Path C:\DRTask\vm-startup-regIpDns_v9.ps1
#below command will read line number 8 and will give you output
    (Get-Content -Path C:\DRTask\vm-startup-regIpDns_v9.ps1 -TotalCount 8)[-1]

"@

Invoke-VMScript -VM $VM -ScriptText $Chpass #-GuestUser "$user" -GuestPassword "$pass"  -ScriptType Powershell

#Start here

Below is output- I got the text in line number8 that that has the IP address in file inside the guest OS.



Basically it read the file with the help of VMware tools in vcenter server.

Cheers! let me know if it worked for you as well. In case of any error please don't shy to put a comment or mail me.




Thank you,
Team vCloudNotes







0 comments:

Post a Comment

Sponsor

AD BANNER
Powered by Blogger.
The Magazine

Text Widget

Facebook

Extra Ads

AD BANNER

Welcome to my Notes!

Hello Folks, My name is Gautam Johar. Actively working on VMware Cloud and keen to learn new and latest cloud technologies in market. Love ...

Contact Form

Name

Email *

Message *

Followers



Labels

Translate

Breaking

Random Posts

Follow Us

On Linkedin

Recent Posts

Recent Comments

Header Ads

Popular Posts

Popular Posts

Recent Posts

Text Widget

Search This Blog

Copyright © test blog | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com