PowerShell – Get Computer name

Background

Wanted to highlight a couple of APIs for retrieving the computer name in Powershell.

Platform

Linux/Cent OS.

 

Outline

  1. Environment Variable
    • Get-ChildItem Env:HOSTNAME
  2. system.environment
    • machineName
  3. system.net.Dns
    • GetHostName
  4. Get-WmiObject ( only works on MS Windows )
    • Win32_ComputerSystem
      • Name

 

Environment Variables

Get-ChildItem Env:

Syntax


pwsh -Command "Get-Childitem Env:"

Output

Get-ChildItem.Env.20181112.0729PM

 

Get-ChildItem Env:HOSTNAME

Syntax


pwsh -Command "Write-Host( (Get-ChildItem Env:HOSTNAME).Value )"

Output

Get-ChildItem.Env.HostName.20181112.0723PM

system.environment

machineName

Syntax


pwsh -Command "Write-Host([system.environment]::machineName)"

Output

system.environment.machineName.20181112.0708PM

system.net.Dns

GetHostName

Syntax


pwsh -Command "Write-Host([system.net.Dns]::GetHostName())

Output

system.net.Dns.GetHostName.20181112.0706PM

 

Get-WmiObject.Win32_ComputerSystem.Name.20181113.0159AM.PNG

Win32_ComputerSystem

Syntax


powershell -Command "Write-Host((Get-WmiObject Win32_ComputerSystem).Name)"

Output

OS – MS Windows

Get-WmiObject.Win32_ComputerSystem.Name.20181113.0159AM.PNG

OS – Linux

Image

Get-WmiObject.Win32_ComputerSystem.Name.Linux.20181113.0203AM

Textual


>pwsh -Command "Write-Host( Write-Host((Get-WmiObject Win32_ComputerSystem).Name))"
Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:25
+ Write-Host( Write-Host((Get-WmiObject Win32_ComputerSystem).Name))
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-WmiObject:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

PowerShell Install On Linux / CentOS

Background

Still preparing our CentOS computer.

Our current step is to Install Microsoft’s PowerShell.

Guide

Our guide is :-

Installing PowerShell Core on Linux
Link

Outline

  1. Install
    • yum
      • Install
        • Install Powershell
      • Registered Repositories – Review
        • yum repolist
        • ls /etc/yum.repos.d
      • Registered Repositories – Update
        • Curl/tee
      • Install
        • Install Powershell
  2. Run Sample Powershell Scripts

Install

Install Powershell

yum install powershell

Syntax


yum install powershell

Output

Output – Image

yum.install.powershell.20181112.1030AM.PNG

Output – Text

>sudo yum install powershell
[sudo] password for dadeniji:
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.hostduplex.com
* extras: mirror.keystealth.org
* updates: mirror.keystealth.org
No package powershell available.
Error: Nothing to do
>

Explanation

Microsoft’s repository not registered on machine.

Registered Repositories – Review

Let us review the yum repositories that we have registered.

yum repolist

Syntax


yum repolist

Output

Output – Image

yum.repolist.20181112.1028AM.PNG

Output – Textual

>yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.sonic.net
* extras: mirrors.usc.edu
* updates: sjc.edge.kernel.org
repo id repo name status
base/7/x86_64 CentOS-7 - Base 9,911
extras/7/x86_64 CentOS-7 - Extras 434
updates/7/x86_64 CentOS-7 - Updates 1,614
repolist: 11,959

 

/etc/yum.repos.d :- List Files

Syntax


ls -la /etc/yum.repos.d

Output

Output – Image

ls.etc.yum.repos.d.20181112.1033AM.PNG

Explanation

  1. The only repositories registered are CentOS

 

Registered Repositories – Update

Create File /etc/yum.repos.d/Microsoft.repo

Let us add Microsoft’s Redhat repository to the list of registered repositories.

Syntax


curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

Output

Output – Image

curl.tee.20181112.1035AM.PNG

Output – Textual

>curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum .repos.d/microsoft.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 193 100 193 0 0 504 0 --:--:-- --:--:-- --:--:-- 505
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
>

 

yum install

Using yum, let us install powershell.

yum install powershell

Syntax


sudo yum install -y powershell

Output

Output – Image
Output – Image – #1

yum.install.powershell.20181112.1037AM.PNG

Output – Image – #2

yum.install.powershell.20181112.1039AM.PNG

Output – Image – #3

yum.install.powershell.20181112.1041AM.PNG

Output – Image – #4

yum.install.powershell.20181112.1043AM.PNG

Output – Image – #5

yum.install.powershell.20181112.1045AM.PNG

 

 

Sample

Run Sample Scripts

Sample #1

Get PowerShell Version Number

Syntax


pwsh -Command "Write-Host((Get-Host).version) "

Output

Output – Image

powerShell.version.20181112.1218PM

Sample #2

Get Username for current user.

Syntax


pwsh -Command "Write-Host( 'Hello ' +  [Environment]::Username) "

Output

Output – Image

helloWorld.20181112.1137AM

 

Summary

Couple of quick points :-

  1. Installation Errors
    • Error :- Repository not available
      • Message
        • No package powershell available.
          Error: Nothing to do
      • Remediation
        • Update Repository – Add Microsoft
  2. In MS Windows, the Powershell executable is powershell.
    In Linux, is is pwsh.

 

 

Keep your laptop running when LID is Closed

Background

There is really not much need to keep a laptop’s lid opened when connected to an external monitor.

OS

Linux

Outline

  1. Launch terminal
  2. sudo to root
  3. edit /etc/systemd/logind.conf
    • Change folder to /etc/systemd
    • Backup current logind.conf
    • Launch editor ( vi) and pass along file name ( logind.conf )
    • Keep current HandleLidSwitch=suspend commented out
    • Add HandleLidSwitch=lock
    • Save Changes
    • Exit Editor
  4. Restart Services
    • Restart systemd-logind.service
      • Command :- systemctl restart systemd-logind.service

 

Images

logind.conf
logind.conf – Original

logind.conf.20181108.0740PM.PNG

logind.conf – Revised

logind.conf.20181108.0746PM.PNG

 

Windows

Outline

  1. Access Control Panel \ Power Options\ System Settings
    • Select “Choose what the Power Buttons do”
    • The “Control Panel\All Control Panel Items\Power Options\System Settings” window appears
      • Access the “Power and sleep buttons and lid settings” group box
      • Focus on “when I close the lid” area
        • There are two options
        • The first been “On Battery” and the other “When plugged in”

Images

Control Panel \ All Control Panel Items \ Power Options \ System Settings

Original

systemSettings.closeLid.20181108.0756PM.PNG

Revised

systemSettings.closeLid.20181108.0758PM.PNG

 

Validation

The steps above were validated on the OSes listed below:

  1. Linux
    • Cent OS
  2. MS Windows
    • Version 10

References

  1. Redhat
    • Products & Services > Product Documentation > Red Hat Enterprise Linux > 7 > Desktop Migration and Administration Guide
      • 13.10. Preventing the Computer from Suspending when Closing the Lid
        Link

CentOS – Blank Screen – No Login

Background

Yesterday, I installed CentOS v7 on a refurbished box.  I went the “Server with GUI” option, but upon starting up for the first time, the usual login screen is not coming up.

I have a dull blank screen, rather than one that lists my username.

Remediation

Idea

Took to the net and found a few people had similar problems.  The most widely promulgated option is to edit the /etc/default/grub configuration file and look for the “GRUB_CMDLINE_LINUX” entry.

And, go on to add “video=LVDS-1:d” to the end of the current contents of the entry.

Steps

Outline

  1. Access Terminal window via pressing the key combination CTRL-ALT-F2
  2. Login from the terminal by entering the username and password
  3. The configuration file /etc/default/grub is read only and so change the file to writable
  4. Edit in vi or your choice editor as sudo
    • Look for the “GRUB_CMDLINE_LINUX” entry and add “video=LVDS-1:d” to the end of the current value.
  5. Reconfigure using grub2-mkconfig
  6. Reboot your computer

 

Details

Here are the steps in detail.

CTRL-ALT-F2

Access Terminal mode by pressing the key combination CTRL-ALT-F2.  The Terminal Screen should appear.

 

Logging from the Terminal

Logging from the Terminal by entering your username and password.

 

Launch vi in sudo mode


sudo vi /etc/default/grub

 

Edit /etc/default/grub

Add ” video=LVDS-1:d
Before

grub-20160813-1143PM ( Before )

Add

grub-20160813-1146PM ( Before)

Reconfig Grub


sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot

reboot

Credit

No original thoughts here!

Credits go out to the guys ( scubastevesama) who spoke about it on Reddit.

And, the ones ( Josef Holland ) who blogged about it.

References

CentOS Login Screen

  1. centos 7 installation issue, no login screen – scubastevesama
    Link
  2. Josef Holland – Disable Laptop LCD Completely on boot
    Link
  3. [RESOLVED] Atom D510 – 6.0 updated to 6.1 – became confused about monitor configuration
    Link
  4. Install on a laptop with external monitor only
    Link

 

Editing /etc/default/grub

  1. Amanda Folson – Modify File Permissions with chmod
    Link
  2. I need to change the Read Only in gedit to Read/Write
    Link

VLC on CentOS – Installation

Prelude

Time was one would have to search around to find Video and Audio codec files to play videos on a personal computer.  But, like Mase and Brandy “I have sat on top of the World” since someone introduced me to VLC.

From that time till now, that is all I use on MS Windows, Apple OSX, and Linux.

 

Background

Googled for tested paths towards installing VLC on CentOS.  The links that came up are:

The instructions basically states that we should avail the EPEL repository along with the RPMForge repository.

 

Repository – EPEL

The EPEL repository contains prerequisite files.

# EPEL6-FAQ
# http://fedoraproject.org/wiki/EPEL6-FAQ
# EPEL6 is an add on repository for RHEL and it's variants. It contains packages that
# are not shipped
sudo yum localinstall --nogpgcheck http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

 

Repository – RPMForge

The RPMForge repository contains the VLC RPM.

We will prepare our system for RPMForge installs by doing the following:

  • Install the repository GPG Key
  • Download the rmpg-release package
  • Verify the downloaded package
  • Install the package
  • Review the installed package

 

Based on the instructions available @ CentOs.org – Additional Resources >> Repositories >> RPMForge (  http://wiki.centos.org/AdditionalResources/Repositories/RPMForge ), here is a quick script that we used.

 

# Install RPMForge
# http://wiki.centos.org/AdditionalResources/Repositories/RPMForge

#Install DAG's GPG key
sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

#Download the package (x64)
sudo wget -O "rpmforge-release-0.5.3-1.el6.rf.i686.rpm"  "http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm"

#Download the package (x32)
sudo wget -O "rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm" "http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm"

#Verify the package you have downloaded
rpm -K rpmforge-release-0.5.3-1.el6.rf.*.rpm

#Install the package
sudo rpm -i rpmforge-release-0.5.3-1.el6.rf.*.rpm

#Review Package
sudo rpm -qa | grep -i rpmforge

 

Ensure VLC RPM Package Availability

Using “yum info“, let us make sure that everything is in place for a good install.

 

Sample :

sudo yum info vlc


Output :

YumInfoVLC

 

 

Install VLC

 

Install VLC via rpm.

Sample :

sudo yum install vlc

 

Output:

InstallVLC

 

Use VLC

Once installed, one can initiate the app from the terminal mode by issuing VLC.

Or via the desktop menu – Sounds & Video \ “VLC Media Player”.

 

 

Error

I experienced a couple of problems preparing the repositories. I was able to scale them through others well lighted path.

I have documented those steps below:

 

Error: Cannot find a valid baseurl for repo: rpmfusion-free

Tried:

sudo yum localinstall –nogpgcheck http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

and

sudo yum localinstall –nogpgcheck http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm

 

But, got the same error:

Error: Cannot find a valid baseurl for repo: rpmfusion-free

 

Solution Guide

How to fix rpmfusion-(non)free repo error in CentOS 6.4
http://www.aliencoders.com/content/how-fix-rpmfusion-nonfree-repo-error-centos-64

 

The steps are:

  • Identify the Repository that rpmfusion is using
  • Remove Fedora RPM Fusion files
  • Install Prerequisite (EPEL 6)

 

Which Repo is rpmfusion* using?

Query active repositories by issuing “yum repolist enabled” request:

Command: 
yum repolist enabled | grep -i rpmfusion

Output:

listRepos for rpmFusion

We can see that rpmFusion is using the one for Fedora 6.


Remove Fedora Files

Remove installed rpmfusion repositories

#RPM Fusion for Fedora 6 - Free
sudo rpm -e rpmfusion-free-release

#RPM Fusion for Fedora 6 - Free - Updates
sudo rpm -e rpmfusion-free-updates-release   

 

 

Identify Redhat CentOS ( EL ) Files

Identify the files that we need:

Visit http://download1.rpmfusion.org/free/ and be sure to identify the URL to the files that we need for EL (Enterprise Linux ).

 

RPMFusion--Free--Folder

 

Install CentOS Files

Here is the script that we used for installing the RPMFusion files:

 

# EPEL6-FAQ
# http://fedoraproject.org/wiki/EPEL6-FAQ
# EPEL6 is an add on repository for RHEL and it's variants. It contains packages RHEL.
# yum local install
sudo yum localinstall --nogpgcheck http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

# Install RPMFusion - v6 - free - works on 32/64 bit
sudo yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm 

# Install RPMFusion - v6 - nonfree - works on 32/64 bit
sudo yum localinstall --nogpgcheck http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm

   

 

 

Error: ERROR 22 – “The requested URL returned error: 403 Forbidden”

 

Tried:

sudo yum localinstall –nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm
But, got the error:

http://centos.alt.ru/repository/centos/6/i386/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 – “The requested URL returned error: 403 Forbidden”

Trying other mirror.

Error: Cannot retrieve repository metadata (repomd.xml) for repository: CentALT. Please verify its path and try again

 

Validate Problem

Review the current contents of the /etc/yum.repos.d/centalt.repo file.

 

Command:

cat /etc/yum.repos.d/centalt.repo

 

Output:

centalt-repo

 

 

Solution Guide

Here is the link we will follow to hopefully repair the problem.

repository metadata (repomd.xml) for repository: mratwork-centalt
http://unix.stackexchange.com/questions/132674/repository-metadata-repomd-xml-for-repository-mratwork-centalt

which states to change from a specific URL to a mirrored one.

In essence we are changing the baseurl from http://centos.alt.ru/repository/centos/6/$basearch/ to http://mirror.sysadminguide.net/centalt/repository/centos/6/$basearch/.

 

Example:

 

# mkdir /etc/yum.repos.d/deprecated/20140823
sudo mkdir -p /etc/yum.repos.d/deprecated/20140823

#backup file
sudo cp /etc/yum.repos.d/centalt.repo /etc/yum.repos.d/deprecated/20140823

#Change baseurl from old to new
#baseurl.new=http://centos.alt.ru/repository/centos/6/$basearch/ 
#baseurl.new=http://mirror.sysadminguide.net/centalt/repository/centos/6/$basearch/ 
sudo sed -i 's/centos.alt.ru/mirror.sysadminguide.net\/centalt/g' /etc/yum.repos.d/centalt.repo

 

References

References – Linux Installation Tools

References – Tool – YUM

 

References – Tool – RPM

 

References – Tool – Generic

 

References – Repository

References – Repository – epel

 

References – RPMForge

 

References – Linux Commands

 

References – Linux Commands – sed

 

References – VLC – Installation

 

References – VLC – Installation – Q&A

 

 

References – Repository – Installation – Errors

 

References – Error – Repository Metadata (respond.xml) for repository – CentAlt

 

References – Error – Fix rpmfusion

 

Technical: Linux – CentOS – Connected Servers Shares not showing up in some “File open” Dialogs

Technical: Linux – CentOS – Connected Servers Shares not showing up in some “File open” Dialogs

Background

In Google Chrome and Firefox, I am a trying to upload some images from a network computer, but those shares are not showing up.

 

Connect to Server

Imagine for a few minutes, you are on your Linux box and you need to connect to your WIndows box and upload some files \ images.

Im my case, my Linux box is a CentOS and so from my desktop, I access the Desktop Menu bar and click on the menu items Places and “Connect To Server …”.

 

ConnectToServer

 

Windows Shares Not Visible

Unfortunately, based on my Application, I have a slightly different Open Dialog:

 

gEdit

gEdit

 

 

Chrome

Chrome

 

 

 

Firefox

 

Firefox

 

The major differences for me is that  in gEdit, I am able to locate my network shares… That slot is “/danieladeniji/<server-name>” and in our example it is only visible (as the last entry on the left panel) in gEdit.

 

Using Samba, Mount Windows Resources\Shares

Install Utilities

Install Utilities – samba-client


sudo yum install samba-client

We are good… as we got back

Package samba-client-3.6.9-168.el6_5.i686 already installed and latest version

 

Install Utilities – samba-common


sudo yum install samba-common

We are good… as we got back

Package samba-common-3.6.9-168.el6_5.i686 already installed and latest version
Nothing to do

 

Install Utilities – cifs-utils

sudo yum install cifs-utils

 

We are good… as we got back

 Package cifs-utils-4.8.1-19.el6.i686 already installed and latest version

Using Samba, Mount Windows Resources\Shares

 

Create Mnt Folder

sudo mkdir /mnt/demobox__DanielAdeniji

Mount Mnt Folder

sudo mount --verbose -t cifs //demobox/DanielAdeniji /mnt/demobox__DanielAdeniji -o username=dadeniji,domain=labdomain,password=candi,sec=ntlm

 

By the way had a lot of problems with this step.  Pasted below are some of incorrect entries we entered and the corresponding errors.

 

Aliased Hostname 

When I tried issuing against an alias name


sudo mount --verbose -t cifs //aliasName/DanielAdeniji /mnt/demobox__DanielAdeniji -o username=dadeniji,domain=labdomain,password=candi,sec=ntlm

 

When we tried obfuscating our hostname by adding an alias name to our hosts files, and targeting that aliasname, here is the error message we get

mount error(5): Input/output error

 

Crediting Pastorino
http://www.linuxquestions.org/questions/linux-networking-3/cifs-mount-error-5-%3D-input-output-error-but-smbfs-works-456897/

 

 

Incorrect Password

If the password is incorrect


sudo mount --verbose -t cifs //demobox/DanielAdeniji /mnt/demobox__DanielAdeniji -o username=dadeniji,domain=labdomain,password=candi,sec=ntlm

wrong password

mount error(13): Permission denied

 

 

If Password contains special characters

If the password contains special characters such as !


sudo mount --verbose -t cifs //demobox/DanielAdeniji /mnt/demobox__DanielAdeniji -o username=dadeniji,domain=labdomain,password=candi!,sec=ntlm

you will get an error message, such as “event not found

bash: !,sec=ntlm: event not found

to correct quote your password

sudo mount --verbose -t cifs //demobox/DanielAdeniji /mnt/demobox__DanielAdeniji -o username=dadeniji,domain=labdomain,password='candi!',sec=ntlm

see we replace candi, with ‘candi!’

 

List Mount Points

Using the mount command, we will list our mount points

Syntax:


mount -v

 

Sample:


mount -v | grep -i "Daniel"

 

Output:

ListMountPointsThatHaveDanielInTheirName

 

 

List Mount Point Contents

Using the mount command, we will list our mount points

Syntax:


ls /mnt/<folder>

 

Sample:


ls /mnt/demobox__DanielAdeniji | more

 

Mounted Folders

So though we still can not view connected servers, we can access our Windows Shares through the mnt folders (/mnt)

 

OpenFile--MountPoints

 

 

Windows Computer Names and Aliases

Btw, to use aliases for MS Windows host names, place them in your /etc/samba/lmhosts file.

etc--samba--lmhosts

 

This is one way you can avoid the “mount error(5): Input/output error” we spoke about earlier.

Keep in mind that trying to use the /etc/hosts will not do.

Dedication

I am going to dedicate this post to Bart and Jorge Castro.  They firmly, yet economically stated this question in a Q/A post titled “gvfs – How do applications open from/save to smb shares? – Ask Ubuntu” ( http://askubuntu.com/questions/224441/how-do-applications-open-from-save-to-smb-shares ).

For me, a newbie, clear and concise concerns helps declutter my space and rather than waste time trying to see if my environment is not properly setup, I can spend cycle trying to bridge seeming implementation gaps.

 

References

References – Mounting Windows Share – Blog

 

References – Mounting Windows Share – Q/A

 

References – Off Topic

Desktop – Linux \ Windows – Unable to move Application Windows as Top Bar is not visible

Background

There are so much we do on the computer that we are not even aware how we do it. For example, moving and resizing a screen we know we click on something and start moving things around.

But, when we can not do it, we try to see if there alternatives to the more obvious pathways.

 

Problem

My problem has occurred a couple of times in the last few days. I am moving things out of the way and then all of a sudden, I am unable to to move the Application Screen back to focus.

 

Topbar-Not-ShowingUp

 

In the image pasted above, I am no longer able to move and resize my Chrome Application.

Solution

I googled for ways to move things around, but was unsuccessful at describing the problem appropriately.

The best help came via:

Ask Leo – I can’t see the top of a window so I can’t minimize/maximize or close – what can I do
http://askleo.com/i_cant_see_the_top_of_a_window_so_i_cant_minimize_maximize_or_close_what_can_i_do-2/

 

His advice is that I should invoke the System Menu, via keystrokes; specifically ALT-spacebar.

So went back to the little window that is still visible and click in the client Area; there by making sure that the Application is the Active Window and thus the recipient of any key.

And, then hold down ALT while pressing the space-bar.

SystemMenu-Small

Once we did so, we have a nice system menu that, and I can now access the “Move” option.

I suppose I could have accessed ALT-F7, all this time.

Prior to know, I was using CTRL-Shift-W to close otherwise orphaned Chrome Windows.

Chrome – Keyboard Shortcuts
https://support.google.com/chromebook/answer/183101?hl=en

 

Thanks Leo.