Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

Powershell Script to send an email when User State Migration Tool process is complete for a machine.

$
0
0

Hello! I am wondering if there is a script someone could write that would send an email when a machine has finished the User State Migration Tool process? The email should contain Computer name, completed time and possibly fully successful or errors encountered status and details for the error(if any). Thanks in advance!




Creating a single computer Managed Service Account (MSA) for scheduled tasks

$
0
0

I have managed to figure out the steps for creating the MSA. And I have used Test-ADseviceAccount and Get-scheduledtask to make sure all the pieces are configured. However, when I use the command shown below to make the service account the user, it automatically switches the task from "Run whether user is logged on or not" to "Run only when user is logged on". The latter makes no sense because you can't logon with an MSA. I can't go in to the scheduled task and change it manually because that requires a password that I don't have (because it is an MSA) and I can't find a powershell command that will let me set it back to the correct setting.

Set-ScheduledTask -TaskPath  '\MyTasks\' -TaskName 'FindComputers' -User 'MyServiceAcnt1$'

Script to reset particular local gpo

$
0
0

Hi

I can reset the local gpo using cmd, but I don't want to reset all. I just want to reset a particular local GPO to Not Configured or default. Is there any script which can solve that.

Thanks

Powershell Script at startup

$
0
0

How I can run powershell script at startup of the VM where My server is not accessible for RDP. (offline server)

I have created .bat file and put it in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\

@ECHO OFF
PowerShell.exe -Command "C:\startup.ps1"


I have put my code in C:\startup.ps1 file. I wan't to know is there any simplest way to achieve this. 

Append to CSV in PowerShell?

$
0
0
I'd like to find a way to append to an outputted csv file in Powershell.  Out-File has too much wasted space and duplicate lines.  Here's the script I'm trying to run:

$a=Get-Content users.txt
foreach ($i in $a)
{
    get-user $i | select displayname,samaccountname | Export-Csv output.csv -notype
}


I can't seem to find anything when dealing with an input file...  Thx.

How to find a protected process's .exe address?

$
0
0
I am writing anti cheat software for a video game. Using CreateToolhelp32Snapshot I get a list of open processes. From there I would like to find the address of the process and read through its .exe file. While this works for most processes, protected processes deny access to methods such as OpenProcess or GetModuleFileNameEx. Is there a work around to finding protected processes addresses?

AD Scripting: Modify all users "End a disconnected session"

$
0
0
Hi guys

I'm looking for a script that will modify all users "End a disconnected session" property to "2 hours". I know you can set this in RDP-Tcp properties and override the individual user settings but I need to set all users to 2 hours and then go and change one to "Never".

It's a Windows 2000 server.

I'm an AD Scripting beginner so I need all the detail I can get.

Thanks

robhob

How to install msi files in silence mode using powershell

$
0
0
Hi,
I am trying to download and install some msi files on Azure environment when role is startup. But I could not acheive correctly. Pls help me out.
My script file is below
md C:\DACFramework$webclient= New-Object System.Net.WebClient# Downloading SQLSysClrTypes.msi$webclient.DownloadFile("http://go.microsoft.com/fwlink/?LinkID=221257&clcid=0x409","C:\DACFramework\SQLSysClrTypes.msi")# Downloading SharedManagementObjects.msi$webclient.DownloadFile("http://go.microsoft.com/fwlink/?LinkID=221285&clcid=0x409","C:\DACFramework\SharedManagementObjects.msi")

cd C:\DACFramework

# Install DAC components using MSIEXECtry {msiexec /i /a SQLSysClrTypes.msi /qn /l*v .\install_SQLSysClrTypes.txtmsiexec /i /a SharedManagementObjects.msi /qn /l*v .\install_SharedManagementObjects.txt

echo INSTALLATION SUCCESSFULLY COMPLETED >> .\install_log.txt
}catch {
echo INSTALLATION ERROR (ERRORLEVEL=%ERRORLEVEL%) >> .\install_log.txt
}

My requirement is to download some msi file as defined in script and install those in silent mode. I tried to use Start-Process instead of msiexec command, I could not do perfectly.
(Start-Process .\SQLSysClrTypes.msi "msiexec /i /a .\SQLSysClrTypes.msi /qn /l*v .\install_SQLSysClrTypes.txt"-Wait -Passthru).ExitCode
(Start-Process .\SharedManagementObjects.msi "msiexec /i /a .\SharedManagementObjects.msi /qn /l*v .\install_SharedManagementObjects.txt"-Wait -Passthru).ExitCode
using msiexec, the files are getting installed but when running it has some issue telling some dll missing. But when I install manually it works fine.
Pls let me know how to install msi files using powershell.
_
Many Thanks, Thirumalai

Autologon Problem

$
0
0

Iwrote this script :

I will ADD computer from domain and set autologon .

When aj run script all is fine in registry , whnen i restart computer autologon id disabled Defaultpassword has removed from registry and autoadminlogon has change to "0"

Can Helpme?Thanks.

Invoke-Command -ComputerName $ComputerName -ScriptBlock {
				Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoAdminLogon -Value "1" -Force -Type String
				Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name DefaultUserName -Value "$Using:username1" -Force
				Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name DefaultPassword -Value "$Using:password1" -Force
				Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name DefaultDomainName -Value "" -Force -ErrorAction SilentlyContinue
				Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name ForceAutoLogon -Value "1"
				Write-Host "Autologon $username1 on $ComputerName is activated"
			}

$pw = "xxxxxxx" | ConvertTo-SecureString -asPlainText -Force
			$usr = "xxxxxxx"
			$creds = New-Object System.Management.Automation.PSCredential($usr, $pw)			
			Add-Computer -ComputerName $ComputerName -Credential $creds -workgroupname WORKGROUP –Verbose –Force	


Unable to apply PNP template due to MFA

$
0
0

I have MFA enabled due to which whenver I run PNP powershell I have to user -useweblogin. But this is also not working when I loop through several sites. 

 

requirement: 1.   Using PNP I have to create 50 Sitecollections :SharePoint online

2. Apply PNPProvisioning Template
3. Associate each site to HUB site. 

4. Enable external Sharing for each. 

 

When I ran below command it will fail after creating first site.  So I have to remove "start-sleep -s 1-" from the script. If I do that, it will create all the sites but "Provisioning template" is applying early without waiting for site to be created properly. Due to which it will fail applying template after 2 sites. 

 

 

Not sure how to fix this. trying since 5days. no luck. 


$TenantUrl = "https://m365x539190-admin.sharepoint.com"
$myHubsite = "https://m365x539190.sharepoint.com/sites/testing"
        Connect-pnpOnline -url $TenantUrl -Credentials -useweblogin
         $siteCollectionList = Import-Csv -Path "C:\sites.csv"
    #Loop through csv and provision site collection from each csv entry
    get-date
    foreach ($siteCollection in $siteCollectionList)
    {
        $SharePointUrl = $siteCollection.Url
        $SiteOwner = $siteCollection.Owner
        $Title = $siteCollection.Title
        $Template = $siteCollection.SiteTemplate
        $TimeZone = $siteCollection.TimeZone
        #Create site collection based on values above        
        New-PnPTenantSite -Owner $SiteOwner -Title $Title -Url $SharePointUrl -Template $Template -TimeZone $TimeZone  -Wait
        write-host "Site Collection $($SharePointUrl) Created Successfully!" -foregroundcolor Green
        get-date
        Start-Sleep -s 10

        #connect to each site that was created earlier and then apply PNP template
        Connect-PnPOnline -Url $SharePointUrl -Credentials -useweblogin
        Apply-PnPProvisioningTemplate -Path C:\template8.xml
        write-host "Template applied $($SharePointUrl) Successfully!" -foregroundcolor Green
          #connect to tenant site again and then add each site to HUB
         Connect-pnpOnline -url $TenantUrl -Credentials -useweblogin
        Add-PnPHubSiteAssociation -Site $SharePointUrl -HubSite $myHubsite
        write-host "Hubsite association of $($SharePointUrl) completed Successfully!" -foregroundcolor Green
        Start-Sleep -s 1
        #Connect to Tenant site again and then connect to each site and enable external sharing
        Connect-PnPOnline -url $TenantUrl -Credentials -useweblogin
        Connect-PnPOnline -Url $SharePointUrl -Credentials -useweblogin
        Set-PnPSite -Identity $SharePointUrl -Sharing ExternalUserSharingOnly -Classification "Private External"
        write-host "External Sharing Enablement for $($SharePointUrl) completed Successfully!" -foregroundcolor Green
        get-date
        }

Powershell: Get and Set printing preferences - default input tray

$
0
0

I have created the following Powershell script.

$ComputerName=$env:computername
$PrinterName="Ahus_Leica"
$PrintConfiguration=Get-PrintConfiguration-ComputerName$ComputerName-PrinterName$PrinterName
$PrintTicketXML=[xml]$PrintConfiguration.PrintTicketXML
$currentTray=($PrintTicketXML.PrintTicket.Feature).where({$_.name-eq'psk:JobInputBin'}).option.name
$NewTray="ns0000:Option4"
$UpdatedPrintTicketXML=$PrintConfiguration.PrintTicketXML-replace"$currentTray","$NewTray"
Set-PrintConfiguration-ComputerName$ComputerName-printername$PrinterName-PrintTicketXML$UpdatedPrintTicketXML

This script successfully changes the printers default input tray. This default value will act as the initial default value for New users accessing the printer in question. (It must be run in context of administrator privileges.)

It does how ever not change the users default input tray in the printing preferences.

I have googled time and time again without being able to find a way to get and set the users printing preferences for this value.

It might be that set-PrinterProperty may be the correct command. I have not been able to verify this as I have not found the correct name for the property in question, nor the correct property value.

I hope there are some one out there able to help me out of my misery.

Many thanks in advance.

The very best regards

Ketil

Get samaccountname from distinguishedname_ powershell

$
0
0

I have an excel file of distinguisednames in this format:
CN=Blow\, Joe,OU=NAME,OU=NAME,DC=NAME,DC=NAME,DC=net

And I want to get the samaccountname of each one of the distinguisedNames.

The name of the header of my excel file is: Users

(I already tried a lot of scripts, but it doesn't work... I never did powershell before.)

Log TCP Connections by Powershell

$
0
0

Referring to following link, I would like to know if I want to log TCP Connections by Powershell, what setup do I need to capture the data?

Does anyone have any suggestions?
Thanks in advance for any suggestions

https://sysadminplus.blogspot.com/2017/08/script-to-log-tcp-connections-by.html


Thanks in advance for any suggestions

How can I stop server process use NTUSER file?

$
0
0

I wrote a script that generates auto-backup .mysql file then compresses this file into .zip file then uploads the .zip file into FTP. after running this script the .sql file was generated but I have a problem in compressing the file step this picture(1) show you what is wrong when I write this command
rar a -pPassword filename.zip>>log file name.

then I use the process explorer and find this process use the NTUSER file this picture(2) to make everything clear

my question is how can I solve this problem? how can I stop these processes and if I stop these processes is it a wrong step or not?

I cant upload pictures yet! 

OneDrive on Demand doing by PowerShell-Script

$
0
0

Would like to use a PS-Script to keep some files and folders Always online and some offline. But it does not work properly. E.g. to keep it offline, here my Script:

$Offline = @(    "$env:OneDrive\Dokumente\folder\*",    "$env:OneDrive\Dokumente\file.xlsx"    )
ForEach ($listOff in $Offline) {    attrib +p -u $listOff /s                       
}

When I change it to "attrib +s +h +p -u" then it worked, but with some negative side-effects. some files then are hidden or become system files.

Thanks for any help


PowerShell : how to generate a digital certificates with exportable private key?

$
0
0

Digital certificates is generated using SelfCert.exe, but export the private key is not available or grayed out.

I would like to know on how to generate a digital certificates with exportable private key using PowerShell.

Does anyone have any suggestions?
Thanks in advance for any suggestions


Thanks in advance for any suggestions

PowerShell - Alert on File Creation

$
0
0

I created this PowerShell script that runs on our web server to alert when a file is created in a folder (C:\webfolder\dumps). The purpose is one of our web services from a third party errors out when a file is created. I created an alert to show on a Cyfe dashboard using iFrame that refreshes every 10 seconds. When there is a file, the background color on the html page is red, otherwise it's green. One thing I noticed is that it seems the html file is deleted, then recreated every time. Is my code wrong? I know it's horrible but I suck at PowerShell and this was hodgepodged, but it works.

$StyleBad = "<style>
    body {color: white;
    background-color: red;}</style>"

$StyleGood = "<style>
    body {color: white;
    background-color: green;}</style>"


while ($GetCount -le 99) {
$GetCount = Get-ChildItem  C:\webfolder\dumps -Recurse -File | Measure-Object | %{$_.Count}

If ($GetCount -le 0) {
ConvertTo-HTML -head $StyleGood -PostContent $GetCount | Out-File C:\website\dumps\index.html
}

else {
ConvertTo-HTML -head $StyleBad -PostContent $GetCount | Out-File C:\website\dumps\index.html
}
}

Checking Groups on all Domains

$
0
0

Hi, 

I need a little help, probably with formatting.  Someone thinks I'm having replication issues on my DCs, I don't think I do.  So, I wrote a script that pulls members from a specific group and checks all DCs.  My point is to add a user to a group, then run my script and do a comparison.  My script is working, however, it shows the results in a funny way.

Clear-Host
$Domain = "domain.net"
$Group = "testuniversal"

#Clear-Host

$DomainServer = (Get-ADDomainController -Discover -DomainName $Domain).Name
$ServerList = Get-ADDomainController -Filter * -Server $DomainServer |Select HostName

#Check if group exist
$GroupExist = "N"
$GroupExist = (Get-ADGroup -Server $DomainServer -Identity $Group).Name

#Get group members
Clear-Host
if($Group -eq $GroupExist)
    {
    foreach ($Server in $ServerList)
        {
        $DCName = $Server.HostName
        Write-Host "."
        Write-Host "Getting member from server $DCName" -ForegroundColor Green
        $ShowUSers = Get-ADGroupMember -Server $DCName -Identity $Group |Select Name -Wait
        $ShowUSers
        }
    }
Else
    {
    Write-Host "Group $Group does not exist"
    }

Although the script works, it displays the output in the wrong format, here's how it looks,

Getting member from server server1.domain.net
.
Getting member from server server2.domain.net
.
Getting member from server server3.domain.net
.
Getting member from server server4.domain.net
Name  
----  
user1
user2
user1
user2
user1
user2
user1
user2
.
Getting member from server serverRO1.domain.net
user1
user2

It looks like it is grouping the first four write-host commands and then displays the first four $ShowUsers variable.  Any ideas anybody?

Thanks.

Inventory Script

$
0
0

Hi,

I have the blow script but it is not working properly. I use a text file filled with the names of the PC's I want to run the script against, then the info is exported to a csv. This works fine on some PC's but not on others. The ones it doesn't work on I get the following error.

Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Management.ManagementObject".

Would anyone be able to fix for me please as I my knowledge is limited and not sure where to go from here?

Many Thanks

Paul

#Test if the text file exisits
If (Test-Path C:\PC_ServerList.txt)
{  
     Write-Host "Importing PC/Server hostnames" -ForegroundColor Yellow
}

Else
{
    Write-Host "Cannot find PC_ServerList.txt text file. Please check if the file exists." -ForegroundColor Red
Continue
}

#Gets the list of PC names
$ComputerList = Get-Content C:\PC_ServerList.txt


#Or $Computerlist = Get-ADComputer -Filter  {OperatingSystem -Like '*Windows Server*' }  | Select-Object -ExpandProperty Name

$OutputCSV = "C:\PC_ServerInventory.csv"
$ScriptPath = $MyInvocation.MyCommand.Path
#$Dir = Split-Path $ScriptPath
Pushd $Dir
[System.Collections.ArrayList]$SysCollection = New-Object System.Collections.ArrayList($Null)
ForEach ($Computer in $ComputerList)
{"Collecting information from $Computer"
    Try
    {

        #Starts the necessary services
        Get-Service -Name WinRM -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
        Get-Service -Name wmiApSrv -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
        Get-Service -Name RemoteRegistry -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
        Get-Service -Name COMSysApp -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
        Get-Service -Name EventSystem -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running


        [WMI]$SysInfo     = Get-WmiObject Win32_ComputerSystem -Namespace "Root\CIMV2" -ComputerName $Computer
        [WMI]$Monitors    = Get-WmiObject WmiMonitorID -Namespace "Root\WMI" -ComputerName $Computer
        [WMI]$BIOS        = Get-WmiObject Win32_BIOS -Namespace "Root\CIMV2" -ComputerName $Computer
        [WMI]$OS          = Get-WmiObject Win32_OperatingSystem -Namespace "Root\CIMV2" -ComputerName $Computer
        [WMI]$Processor   = Get-WmiObject Win32_Processor -Namespace "Root\CIMV2" -ComputerName $Computer
        [WMI]$AV          = Get-WmiObject AntiVirusProduct -Namespace "Root\SecurityCenter2" -ComputerName $Computer
        [WMI]$LastUser    = Get-WmiObject Win32_Process -Namespace "Root\CIMV2" -ComputerName $Computer | Where-Object Name -Match Explorer
        [WMI]$TimeZone    = Get-WmiObject Win32_TimeZone -Namespace "Root\CIMV2" -ComputerName $Computer
        [Array]$Disks     = Get-WmiObject Win32_LogicalDisk -Namespace "Root\CIMV2" -ComputerName $Computer -Filter DriveType=3
        [Array]$USBDisks  = Get-WmiObject Win32_LogicalDisk -Namespace "Root\CIMV2" -ComputerName $Computer -Filter DriveType=2
        [Array]$NIC       = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "Root\CIMV2" -ComputerName $Computer -Filter 'IPEnabled = "True"'

        #Selects the Administrator 
        $LocalAdmin       = Invoke-Command -ComputerName $Computer {Get-LocalUser -Name "Administrator"}

        #Gets the AV Last updated time/date
        $AVDU             = Invoke-Command -ComputerName $Computer {Get-MpComputerStatus | Select-Object -Property AntivirusSignatureLastUpdated}

        #Gets the release ID Number
        $OSVersion        = Invoke-command -ComputerName $Computer {Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"}

        #Gets the system uptime
        $LastBoot         = [System.Management.ManagementDateTimeConverter]::ToDateTime("$($OS.LastBootUpTime)")
        $UpTime           = (Get-Date) - $LastBoot

        #Switch for the AV Real Time Protection and Definition Status
         Switch ($AV.ProductState){
        "262144" {$DefStatus = "Up to date" ;$RTStatus = "Disabled"} "262160" {$DefStatus = "Out of date" ;$RTStatus = "Disabled"} "266240" {$DefStatus = "Up to date" ;$RTStatus = "Enabled"} "266256" {$DefStatus = "Out of date" ;$RTStatus = "Enabled"} "393216" {$DefStatus = "Up to date" ;$RTStatus = "Disabled"} "393232" {$DefStatus = "Out of date" ;$RTStatus = "Disabled"} "393488" {$DefStatus = "Out of date" ;$RTStatus = "Disabled"} "397312" {$DefStatus = "Up to date" ;$RTStatus = "Enabled"} "397328" {$DefStatus = "Out of date" ;$RTStatus = "Enabled"} "397584" {$DefStatus = "Out of date" ;$RTStatus = "Enabled"}"397568" {$DefStatus = "Up to date"; $RTStatus = "Enabled"}"393472" {$DefStatus = "Up to date" ;$RTStatus = "Disabled"} 
         Default {$DefStatus = "Unknown" ;$RTStatus = "Unknown"}}

         #Switch to list the name of the OS Language
         Switch ($OS.OSLanguage){
        "1078"  {$OSLan = "Afrikaans - South Africa"}"1052"  {$OSLan = "Albanian - Albania"}"1118"  {$OSLan = "Amharic - Ethiopia"}"1025"  {$OSLan = "Arabic - Saudi Arabia"}"5121"  {$OSLan = "Arabic - Algeria"}"15361" {$OSLan = "Arabic - Bahrain"}"3073"  {$OSLan = "Arabic - Egypt"}"2049"  {$OSLan = "Arabic - Iraq"}"11265" {$OSLan = "Arabic - Jordan"}"13313" {$OSLan = "Arabic - Kuwait"}"12289" {$OSLan =  "Arabic - Lebanon"}"4097"  {$OSLan = "Arabic - Libya"}"6145"  {$OSLan = "Arabic - Morocco"}"8193"  {$OSLan = "Arabic - Oman"}"16385" {$OSLan = "Arabic - Qatar"}"10241" {$OSLan = "Arabic - Syria"}"7169"  {$OSLan = "Arabic - Tunisia"}"14337" {$OSLan = "Arabic - U.A.E."}"9217"  {$OSLan = "Arabic - Yemen"}"1067"  {$OSLan = "Armenian - Armenia"}"1101"  {$OSLan = "Assamese"}"2092"  {$OSLan = "Azeri (Cyrillic)"}"1068"  {$OSLan = "Azeri (Latin)"}"1069"  {$OSLan = "Basque"}"1059"  {$OSLan = "Belarusian"}"1093"  {$OSLan = "Bengali (India)"}"2117"  {$OSLan = "Bengali (Bangladesh)"}"5146"  {$OSLan = "Bosnian (Bosnia/Herzegovina)"}"1026"  {$OSLan = "Bulgarian"}"1109"  {$OSLan = "Burmese"}"1027"  {$OSLan = "Catalan"}"1116"  {$OSLan = "Cherokee - United States"}"2052"  {$OSLan = "Chinese - People's Republic of China"} "4100"  {$OSLan = "Chinese - Singapore"}"1028"  {$OSLan = "Chinese - Taiwan"}"3076"  {$OSLan = "Chinese - Hong Kong SAR"}"5124"  {$OSLan = "Chinese - Macao SAR"}"1050"  {$OSLan = "Croatian"}"4122"  {$OSLan = "Croatian (Bosnia/Herzegovina)"}"1029"  {$OSLan = "Czech"}"1030"  {$OSLan = "Danish"}"1125"  {$OSLan = "Divehi"}"1043"  {$OSLan = "Dutch - Netherlands"}"2067"  {$OSLan = "Dutch - Belgium"}"1126"  {$OSLan = "Edo"}"1033"  {$OSLan = "English - United States"}"2057"  {$OSLan = "English - United Kingdom"}"3081"  {$OSLan = "English - Australia"}"10249" {$OSLan = "English - Belize"}"4105"  {$OSLan = "English - Canada"}"9225"  {$OSLan = "English - Caribbean"}"15369" {$OSLan = "English - Hong Kong SAR"}"16393" {$OSLan = "English - India"}"14345" {$OSLan = "English - Indonesia"}"6153"  {$OSLan = "English - Ireland"}"8201"  {$OSLan = "English - Jamaica"}"17417" {$OSLan = "English - Malaysia"}"5129"  {$OSLan = "English - New Zealand"}"13321" {$OSLan = "English - Philippines"}"18441" {$OSLan = "English - Singapore"}"7177"  {$OSLan = "English - South Africa"}"11273" {$OSLan = "English - Trinidad"}"12297" {$OSLan = "English - Zimbabwe"}"1061"  {$OSLan = "Estonian"}"1080"  {$OSLan = "Faroese"}"1065"  {$OSLan = "Farsi"}"1124"  {$OSLan = "Filipino"}"1035"  {$OSLan = "Finnish"}"1036"  {$OSLan = "French - France"}"2060"  {$OSLan = "French - Belgium"}"11276" {$OSLan = "French - Cameroon"}"3084"  {$OSLan = "French - Canada"}"9228"  {$OSLan = "French - Democratic Rep. of Congo"}"12300" {$OSLan = "French - Cote d'Ivoire"}"15372" {$OSLan = "French - Haiti"}"5132"  {$OSLan = "French - Luxembourg "}"13324" {$OSLan = "French - Mali"}"6156"  {$OSLan = "French - Monaco"}"14348" {$OSLan = "French - Morocco"}"58380" {$OSLan = "French - North Africa"}"8204"  {$OSLan = "French - Reunion"}"10252" {$OSLan = "French - Senegal"}"4108"  {$OSLan = "French - Switzerland"}"7180"  {$OSLan = "French - West Indies"}"1122"  {$OSLan = "Frisian - Netherlands"}"1127"  {$OSLan = "Fulfulde - Nigeria"}"1071"  {$OSLan = "FYRO Macedonian"}"2108"  {$OSLan = "Gaelic (Ireland)"}"1084"  {$OSLan = "Gaelic (Scotland)"}"1110"  {$OSLan = "Galician"}"1079"  {$OSLan = "Georgian"}"1031"  {$OSLan = "German - Germany"}"3079"  {$OSLan = "German - Austria"}"5127"  {$OSLan = "German - Liechtenstein"}"4103"  {$OSLan = "German - Luxembourg"}"2055"  {$OSLan = "German - Switzerland"}"1032"  {$OSLan = "Greek"}"1140"  {$OSLan = "Guarani - Paraguay"}"1095"  {$OSLan = "Gujarati"}"1128"  {$OSLan = "Hausa - Nigeria"}"1141"  {$OSLan = "Hawaiian - United States"}"1037"  {$OSLan = "Hebrew"}"1081"  {$OSLan = "Hindi"}"1038"  {$OSLan =" Hungarian"}"1129"  {$OSLan = "Ibibio - Nigeria"}"1039"  {$OSLan = "Icelandic"}"1136"  {$OSLan = "Igbo - Nigeria"}"1057"  {$OSLan = "Indonesian"}"1117"  {$OSLan = "Inuktitut"}"1040"  {$OSLan = "Italian - Italy"}"2064"  {$OSLan = "Italian - Switzerland"}"1041"  {$OSLan = "Japanese"}"1099"  {$OSLan = "Kannada"}"1137"  {$OSLan = "Kanuri - Nigeria"}"2144"  {$OSLan = "Kashmiri"}"1120"  {$OSLan = "Kashmiri (Arabic)"}"1087"  {$OSLan = "Kazakh"}"1107"  {$OSLan = "Khmer"}"1111"  {$OSLan = "Konkani"}"1042"  {$OSLan = "Korean"}"1088"  {$OSLan = "Kyrgyz (Cyrillic)"}"1108"  {$OSLan = "Lao"}"1142"  {$OSLan = "Latin"}"1062"  {$OSLan = "Latvian"}"1063"  {$OSLan = "Lithuanian"}"1086"  {$OSLan = "Malay - Malaysia"}"2110"  {$OSLan = "Malay - Brunei Darussalam"}"1100"  {$OSLan = "Malayalam"}"1082"  {$OSLan = "Maltese"}"1112"  {$OSLan = "Manipuri"}"1153"  {$OSLan = "Maori - New Zealand"}"1102"  {$OSLan = "Marathi"}"1104"  {$OSLan = "Mongolian (Cyrillic)"}"2128"  {$OSLan = "Mongolian (Mongolian)"}"1121"  {$OSLan = "Nepali"}"2145"  {$OSLan = "Nepali - India"}"1044"  {$OSLan = "Norwegian (Bokmål)"}"2068"  {$OSLan = "Norwegian (Nynorsk)"}"1096"  {$OSLan = "Oriya"}"1138"  {$OSLan = "Oromo"}"1145"  {$OSLan = "Papiamentu"}"1123"  {$OSLan = "Pashto"}"1045"  {$OSLan = "Polish"}"1046"  {$OSLan = "Portuguese - Brazil"}"2070"  {$OSLan = "Portuguese - Portugal"}"1094"  {$OSLan = "Punjabi"}"2118"  {$OSLan = "Punjabi (Pakistan)"}"1131"  {$OSLan = "Quecha - Bolivia"}"2155"  {$OSLan = "Quecha - Ecuador"}"3179"  {$OSLan = "Quecha - Peru"}"1047"  {$OSLan = "Rhaeto-Romanic"}"1048"  {$OSLan = "Romanian"}"2072"  {$OSLan = "Romanian - Moldava"}"1049"  {$OSLan = "Russian"}"2073"  {$OSLan = "Russian - Moldava"}"1083"  {$OSLan = "Sami (Lappish)"}"1103"  {$OSLan = "Sanskrit"}"1132"  {$OSLan = "Sepedi"}"3098"  {$OSLan = "Serbian (Cyrillic)"}"2074"  {$OSLan = "Serbian (Latin)"}"1113"  {$OSLan = "Sindhi - India"}"2137"  {$OSLan = "Sindhi - Pakistan"}"1115"  {$OSLan = "Sinhalese - Sri Lanka"}"1051"  {$OSLan = "Slovak"}"1060"  {$OSLan = "Slovenian"}"1143"  {$OSLan = "Somali"}"1070"  {$OSLan = "Sorbian"}"3082"  {$OSLan = "Spanish - Spain (Modern Sort)"}"1034"  {$OSLan = "Spanish - Spain (Traditional Sort)"}"11274" {$OSLan = "Spanish - Argentina"}"16394" {$OSLan = "Spanish - Bolivia"}"13322" {$OSLan = "Spanish - Chile"}"9226"  {$OSLan = "Spanish - Colombia"}"5130"  {$OSLan = "Spanish - Costa Rica"}"7178"  {$OSLan = "Spanish - Dominican Republic"}"12298" {$OSLan = "Spanish - Ecuador"}"17418" {$OSLan = "Spanish - El Salvador"}"4106"  {$OSLan = "Spanish - Guatemala"}"18442" {$OSLan = "Spanish - Honduras"}"22538" {$OSLan = "Spanish - Latin America"}"2058"  {$OSLan = "Spanish - Mexico"}"19466" {$OSLan = "Spanish - Nicaragua"}"6154"  {$OSLan = "Spanish - Panama"}"15370" {$OSLan = "Spanish - Paraguay"}"10250" {$OSLan = "Spanish - Peru"}"20490" {$OSLan = "Spanish - Puerto Rico"}"21514" {$OSLan = "Spanish - United States"}"14346" {$OSLan = "Spanish - Uruguay"}"8202"  {$OSLan = "Spanish - Venezuela"}"1072"  {$OSLan = "Sutu"}"1089"  {$OSLan = "Swahili"}"1053"  {$OSLan = "Swedish"}"2077"  {$OSLan = "Swedish - Finland"}"1114"  {$OSLan = "Syriac"}"1064"  {$OSLan = "Tajik"}"1119"  {$OSLan = "Tamazight (Arabic)"}"2143"  {$OSLan = "Tamazight (Latin)"}"1097"  {$OSLan = "Tamil"}"1092"  {$OSLan = "Tatar"}"1098"  {$OSLan = "Telugu"}"1054"  {$OSLan = "Thai"}"2129"  {$OSLan = "Tibetan - Bhutan"}"1105"  {$OSLan = "Tibetan - People's Rep. of China"}"2163"  {$OSLan = "Tigrigna - Eritrea"}"1139"  {$OSLan = "Tigrigna - Ethiopia"}"1073"  {$OSLan = "Tsonga"}"1074"  {$OSLan = "Tswana"}"1055"  {$OSLan = "Turkish"}"1090"  {$OSLan = "Turkmen"}"1152"  {$OSLan = "Uighur - China"}"1058"  {$OSLan = "Ukrainian"}"1056"  {$OSLan = "Urdu"}"2080"  {$OSLan = "Urdu - India"}"2115"  {$OSLan = "Uzbek (Cyrillic)"}"1091"  {$OSLan = "Uzbek (Latin)"}"1075"  {$OSLan = "Venda"}"1066"  {$OSLan = "Vietnamese"}"1106"  {$OSLan = "Welsh"}"1076"  {$OSLan = "Xhosa"}"1144"  {$OSLan = "Yi"}"1085"  {$OSLan = "Yiddish"}"1130"  {$OSLan = "Yoruba"}"1077"  {$OSLan = "Zulu"}"1279"  {$OSLan = "HID (Human Interface Device)"}}
        #Switch to list the name of the monitor manufacturer
        Switch ($MonManufacturer){"AAC"   {$MonFriendlyName =	"AcerView"}"ACR"   {$MonFriendlyName = "Acer"}"AOC"   {$MonFriendlyName = "AOC"}"AIC"   {$MonFriendlyName = "AG Neovo"}"APP"   {$MonFriendlyName = "Apple Computer"}"AST"   {$MonFriendlyName = "AST Research"}"AUO"   {$MonFriendlyName = "Asus"}"BNQ"   {$MonFriendlyName = "BenQ"}"CMO"   {$MonFriendlyName = "Acer"}"CPL"   {$MonFriendlyName = "Compal"}"CPQ"   {$MonFriendlyName = "Compaq"}"CPT"   {$MonFriendlyName = "Chunghwa Pciture Tubes, Ltd."}"CTX"   {$MonFriendlyName = "CTX"}"DEC"   {$MonFriendlyName = "DEC"}"DEL"   {$MonFriendlyName = "Dell"}"DPC"   {$MonFriendlyName = "Delta"}"DWE"   {$MonFriendlyName = "Daewoo"}"EIZ"   {$MonFriendlyName = "EIZO"}"ELS"   {$MonFriendlyName = "ELSA"}"ENC"   {$MonFriendlyName = "EIZO"}"EPI"   {$MonFriendlyName = "Envision"}"FCM"   {$MonFriendlyName = "Funai"}"FUJ"   {$MonFriendlyName = "Fujitsu"}"FUS"   {$MonFriendlyName = "Fujitsu-Siemens"}"GSM"   {$MonFriendlyName = "LG Electronics"}"GWY"   {$MonFriendlyName = "Gateway 2000"}"HEI"   {$MonFriendlyName = "Hyundai"}"HIT"   {$MonFriendlyName = "Hyundai"}"HSD"   {$MonFriendlyName = "Hanns-G"}"HSL"   {$MonFriendlyName = "Hansol"}"HTC"   {$MonFriendlyName = "Hitachi/Nissei"}"HWP"   {$MonFriendlyName = "HP"}"IBM"   {$MonFriendlyName = "IBM"}"ICL"   {$MonFriendlyName = "Fujitsu ICL"}"IVM"   {$MonFriendlyName = "Iiyama"}"KDS"   {$MonFriendlyName = "Korea Data Systems"}"LEN"   {$MonFriendlyName = "Lenovo"}"LGD"   {$MonFriendlyName = "Asus"}"LPL"   {$MonFriendlyName = "Fujitsu"}"MAX"   {$MonFriendlyName = "Belinea"}"MEI"   {$MonFriendlyName = "Panasonic"}"MEL"   {$MonFriendlyName = "Mitsubishi Electronics"}"MS_"   {$MonFriendlyName = "Panasonic"}"NAN"   {$MonFriendlyName = "Nanao"}"NEC"   {$MonFriendlyName = "NEC"}"NOK"   {$MonFriendlyName = "Nokia Data"}"NVD"   {$MonFriendlyName = "Fujitsu"}"OPT"   {$MonFriendlyName = "Optoma"}"PHL"   {$MonFriendlyName = "Philips"}"REL"   {$MonFriendlyName = "Relisys"}"SAN"   {$MonFriendlyName = "Samsung"}"SAM"   {$MonFriendlyName = "Samsung"}"SBI"   {$MonFriendlyName = "Smarttech"}"SGI"   {$MonFriendlyName = "SGI"}"SNY"   {$MonFriendlyName = "Sony"}"SRC"   {$MonFriendlyName = "Shamrock"}"SUN"   {$MonFriendlyName = "Sun Microsystems"}"SEC"   {$MonFriendlyName = "Hewlett-Packard"}"TAT"   {$MonFriendlyName = "Tatung"}"TOS"   {$MonFriendlyName = "Toshiba"}"TSB"   {$MonFriendlyName = "Toshiba"}"VSC"   {$MonFriendlyName = "ViewSonic"}"ZCM"   {$MonFriendlyName = "Zenith"}"UNK"   {$MonFriendlyName = "Unknown"}"_YV"   {$MonFriendlyName = "Fujitsu"}
        }

#Get the monitor Model, Serial and Product Number
Function Decode {
    If ($Args[0] -Is [System.Array]) {
        [System.Text.Encoding]::ASCII.GetString($Args[0]).Replace("$([char]0x0000)","") -join ""
    }
    Else {
        Continue
    }
}

ForEach ($Monitor in $Monitors) {  
    $MonModelNumber = Decode $Monitor.UserFriendlyName -Ne 0
    $MonSerialNumber = Decode $Monitor.SerialNumberID -Ne 0
    $MonManufacturer = Decode $Monitor.ManufacturerName -Ne 0
    $MonProductNumber = Decode $Monitor.ProductCodeID -Ne 0

}

#Gets the installed and missing Windows Updates
$UpdateSession = [Activator]::CreateInstance([Type]::GetTypeFromProgID("Microsoft.Update.Session",$Computer))
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$MissingUpdates = @($UpdateSearcher.Search("DeploymentAction=* and IsHidden=0 and Type='Software' and IsInstalled=0").Updates)
$InstalledUpdates = @($UpdateSearcher.Search("IsHidden=0 and Type='Software' and IsInstalled=1").Updates)

        
    $SI = @{
            FQDN                          = [String]$SysInfo.DNSHostName+"."+$SysInfo.Domain
            NetBIOSName                   = [String]$SysInfo.DNSHostName
            Domain                        = [String]$SysInfo.Domain
            Manufacturer                  = [String]$SysInfo.Manufacturer
            Model                         = [String]$SysInfo.Model
            SystemType                    = [String]$SysInfo.SystemType
            TotalMemory                   = "$([String]([System.Math]::Round($SysInfo.TotalPhysicalMemory/1GB,2))) GB"
            BIOSName                      = [String]$BIOS.Name
            BIOSDescription               = [String]$BIOS.Description
            BIOSVersion                   = [String]$BIOS.SMBIOSBIOSVersion+"."+$BIOS.SMBIOSMajorVersion+"."+$BIOS.SMBIOSMinorVersion
            BIOSManufacturer              = [String]$BIOS.Manufacturer
            SerialNo                      = [String]$BIOS.SerialNumber
            OSName                        = [String]$OS.Caption
            OSLanguage                    = [String]$OSLan
            OSServicePack                 = (“SP {0}” -F [String]$OS.ServicePackMajorVersion)
            OSArchitecture                = [String]$OS.OSArchitecture
            OSBuildNo                     = [String]$OS.BuildNumber+"."+$OSVersion.UBR
            OSVersion                     = [String]$OS.Version            
            OSReleaseNo                   = [String]$OSVersion.ReleaseID
            OSInstallDate                 = [String]$OS.ConvertToDateTime($OS.InstallDate) -F "MM/dd/yyyy"
            TimeZone                      = [String]$TimeZone.StandardName
            PhysicalProcessors            = [String]@($Processor).Count
            LogicalProcessors             = [String]$Processor.NumberOfLogicalProcessors
            ProcessorModel                = [String]$Processor.Name
            ProcessorManufacturer         = [String]$Processor.Manufacturer
            Cores                         = [String]$Processor.NumberOfCores
            IPAddress                     = [String]$NIC.IPAddress
            MACAddress                    = [String]$NIC.MACAddress
            AVStatus                      = [String]$DefStatus
            RTProtection                  = [String]$RTStatus
            AVLastUpdate                  = [String]$AVDU.AntivirusSignatureLastUpdated
            AntiVirus                     = [String]$AV.DisplayName
            UpTime                        = [String]$UpTime.Days.ToString()+" Days, "+$UpTime.Hours.ToString()+" Hours, "+$UpTime.Minutes.ToString()+" Minutes, "+$UpTime.Seconds.ToString()+" Seconds"
            AdministratorAccountEnabled   = [String]$LocalAdmin.Enabled
            LastUser                      = [String]$LastUser.GetOwner().User
            InstalledWinUpdates           = [String]$InstalledUpdates.Title
            MissingWinUpdates             = [String]$MissingUpdates.Title
            MonitorManufacturer           = [String]$MonFriendlyName
            MonitorModel                  = [String]$MonModelNumber
            MonitorProductNo              = [String]$MonProductNumber
            MonitorSerialNo               = [String]$MonSerialNumber
            }
        $Disks    | ForEach-Object {$SI."DriveSize:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.Size/1GB,2))) GB"} -ErrorAction SilentlyContinue
        $Disks    | ForEach-Object {$SI."FreeDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.FreeSpace/1GB,2))) GB"} -ErrorAction SilentlyContinue
        $Disks    | ForEach-Object {$SI."UsedDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round(($_.Size - $_.FreeSpace)/1GB,2))) GB"} -ErrorAction SilentlyContinue
        $USBDisks | ForEach-Object {$SI."DriveSize:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.Size/1GB,2))) GB"} -ErrorAction SilentlyContinue
        $USBDisks | ForEach-Object {$SI."FreeDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.FreeSpace/1GB,2))) GB"} -ErrorAction SilentlyContinue
        $USBDisks | ForEach-Object {$SI."UsedDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round(($_.Size - $_.FreeSpace)/1GB,2))) GB"} -ErrorAction SilentlyContinue
    }
    Catch [Exception]
    {
        Write-Host "Error communicating with $Computer, skipping to next" -ForegroundColor White -BackgroundColor Red
        $SI = @{
            Server          = [String]$Computer
            ErrorMessage    = [String]$_.Exception.Message
            ErrorItem       = [String]$Computer
    }
    Continue
}
    Finally
    {
        [Void]$SysCollection.Add((New-Object PSObject -Property $SI))   
    }
}
$SysCollection `
    | Select-Object FQDN,NetBIOSName,Domain,Manufacturer,Model,SerialNo,SystemType,ProcessorManufacturer,ProcessorModel,PhysicalProcessors,LogicalProcessors,Cores,TotalMemory,IPAddress,MACAddress,MonitorManufacturer,MonitorModel,MonitorProductNo,MonitorSerialNo,BIOSName,BIOSManufacturer,BiosDescription,BiosVersion,OSName,OSVersion,OSBuildNo,OSReleaseNo,OSArchitecture,OSServicePack,OSLanguage,OSInstallDate,InstalledWinUpdates,MissingWinUpdates,TimeZone,AntiVirus,AVStatus,RTProtection,AVLastUpdate,UpTime,LastUser,AdministratorAccountEnabled,DriveSize:A,DriveSize:B,DriveSize:C,DriveSize:D,DriveSize:E,DriveSize:F,DriveSize:G,DriveSize:H,DriveSize:I,DriveSize:J,DriveSize:K,DriveSize:L,DriveSize:M,DriveSize:N,DriveSize:O,DriveSize:P,DriveSize:Q,DriveSize:R,DriveSize:S,DriveSize:T,DriveSize:U,DriveSize:V,DriveSize:W,DriveSize:X,DriveSize:Y,DriveSize:Z,UsedDriveSpace:A,UsedDriveSpace:B,UsedDriveSpace:C,UsedDriveSpace:D,UsedDriveSpace:E,UsedDriveSpace:F,UsedDriveSpace:G,UsedDriveSpace:H,UsedDriveSpace:I,UsedDriveSpace:J,UsedDriveSpace:K,UsedDriveSpace:L,UsedDriveSpace:M,UsedDriveSpace:N,UsedDriveSpace:O,UsedDriveSpace:P,UsedDriveSpace:Q,UsedDriveSpace:R,UsedDriveSpace:S,UsedDriveSpace:T,UsedDriveSpace:U,UsedDriveSpace:V,UsedDriveSpace:W,UsedDriveSpace:X,UsedDriveSpace:Y,UsedDriveSpace:Z,FreeDriveSpace:A,FreeDriveSpace:B,FreeDriveSpace:C,FreeDriveSpace:D,FreeDriveSpace:E,FreeDriveSpace:F,FreeDriveSpace:G,FreeDriveSpace:H,FreeDriveSpace:I,FreeDriveSpace:J,FreeDriveSpace:K,FreeDriveSpace:L,FreeDriveSpace:M,FreeDriveSpace:N,FreeDriveSpace:O,FreeDriveSpace:P,FreeDriveSpace:Q,FreeDriveSpace:R,FreeDriveSpace:S,FreeDriveSpace:T,FreeDriveSpace:U,FreeDriveSpace:V,FreeDriveSpace:W,FreeDriveSpace:X,FreeDriveSpace:Y,FreeDriveSpace:Z,ErrorMessage,ErrorItem `
    | Export-CSV -Path $OutputCSV -NoTypeInformation
      Write-Host "Inventory completed. Check $OutputCSV" -ForegroundColor Green

Powershell check the given day with the current day

$
0
0
First of all, sorry for my crappy English.
I need to set up a script which checks the given day with the current day. Like, it's Tuesday and the user says Tuesday; the bot has to check this and if it's both correct and incorrect, the bot has to give an answer. The answer needs to be in Dutch. 
Viewing all 15028 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>