LINUX – Samba and Windows

I often find myself connecting to shares from  Windows to Linux and vice versa and I keep forgetting the commands – so here it is:

Connecting to a Windows share from Linux:

  • install winbind, cifs-utils and smbclient packages
  • change nsswitch.conf file (add/change this line: hosts: files wins dns ), then restart network
  • to see what shares are available on Windows box:
root@server1# smbclient -L // -U username
Enter username's password:
Domain=[contoso] OS=[Windows Server 2008 R2 Datacenter 7601 Service Pack 1] Server=[Windows Server 2008 R2 Datacenter 6.1]

Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
share Disk
  • Mount the Windows share from console
mount -t cifs // test -o username=linuxacademy,password=123456,rw,nounix,file_mode=0777
  • Mount the Windows share via fstab

>pre># stuff to put in the /etc/fstab file
# remote windows file share
// /mnt/test cifs credentials=/root/.smbcredentials,rw,nounix,file_mode=0777,dir_mode=0777 0 0

and create the .smbcredentials file under root:


Connecting to a Linux share from Windows (configuring samba):

  • Install samba and samba-common
  • Configure /etc/samba/smb.conf file – add or uncomment and modify this section:
   comment = Home Directories
   browseable = no
   writable = yes

   comment = Defalt Share
   path = /share/
   force user = samba
   force group = samba
   read only = no
   hosts allow =

Restart samba: service smbd restart

  • create samba username that matches windows account password:
root@server1:/# smbpasswd -a windows_username
New SMB password:
Retype new SMB password:
Added user windows_username.

Powershell – list installed updates

Save this as as for example find-windowsUpdate.ps1 script:

$computer = read-host "Enter computer name"
$patch = read-host "Specify update KB number or enter * to list all updates"
Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName $computer | select description,hotfixid,installedon | where hotfixid -eq $patch


usage example:



WSUS – list computers needing a restart

Prerequisites – Must have a WSUS management tools installed on the computer that you are running this script,

$updateServer = “WSUS SERVER NAME or IP Address“
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$false)
$computerScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope;
$computerScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
$updateScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::InstalledPendingReboot;
$computers = $wsus.GetComputerTargets($computerScope);

$computers | select FullDomainName,IPaddress | Sort-Object -Property IPaddress
$count = $computers | Measure-Object;

Write-host "";
write-host "Total number of objects: "$count.count;

Change the $updateServer to you WSUS server name or IP address.

PowerShell script to approve WSUS updates

Here is a short script that is very useful to approve missing updates for a specific server:


$updateServer = “WSUS.server.IP.address“

$machineName = Read-Host “enter DNS name of the computer you wish to approve updates for“

$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$false)

$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope

$updateScope.includedInstallationStates = “NotInstalled“

$com = $wsus.GetComputerTargetByName($machineName)

$groupname =  Read-Host “Enter target WSUS group name”
$Target = $wsus.GetComputerTargetGroups() | where {$_.Name -eq $groupname}

$action = [Microsoft.UpdateServices.Administration.UpdateApprovalAction]::Install

$updates = $com.GetUpdateInstallationInfoPerUpdate($updateScope)
$updates | foreach-object {$uid = $_.UpdateId; $u = $wsus.GetUpdate($uid); $u.Title; $u.Approve($action,$target);}