windows
98 Topicschanging file attribute/metadata
Hello all, when I run a script that gives all of the file properties, I can see one named 'protected' and the value is 'yes'? Now I want this changed to 'No'. I am new to powershell and have been searching everywhere, but did not find any solution for my issue. The script I run to get the file information looks like this: $objShell = New-Object -ComObject Shell.Application $objFolder = $objShell.Namespace((Get-Item .).FullName) $filenameWithExtension = "24 Africa (Single Version).m4a" $objFile = $objFolder.ParseName($filenameWithExtension) $fileMeta = [ordered]@{} for($id = 0; $id -le 266; $id++){ $fileMeta[ $($objFolder.GetDetailsOf($objFolder, $id)) ] = $( if($objFolder.GetDetailsOf($objFile, $id)){ $($objFolder.GetDetailsOf($objFile, $id)) }else{ "" } ) } print ordered hashtable $fileMeta you get a list of properties and one of them is the Protected. Can anyone help on this? thx60Views0likes6CommentsPowershell error when using install-module
Hello ! when I use Install-Module -Name ExchangeOnlineManagement I get the following error : Install-Package: The module 'ExchangeOnlineManagement' cannot be installed or updated because the authenticode signature of the file 'ExchangeOnlineManagement.psd1' is not valid. I use powershell 7.5.0 Any help is welcome. best regardsSolved107Views0likes2CommentsWindows Restricted User Experience Set-CimInstance Error
So I'm trying to set up a restricted user experience that allows the usage of only one application. However, I keep running into this weird error message that provides no useful information: I've been successful in getting the boilerplate example from the official Windows guide to work, so I'm fairly certain the error lies in how I've set up the Allowed Apps and PinnedList. Perhaps in the path to the app? But I'm not sure how I'd go about changing that since I got the pathway from the task manager. Any help is appreciated! Full code below: psexec.exe -i -s powershell.exe $assignedAccessConfiguration = @" <?xml version="1.0" encoding="utf-8"?> <AssignedAccessConfiguration xmlns="http://schemas.microsoft.com/AssignedAccess/2017/config" xmlns:rs5="http://schemas.microsoft.com/AssignedAccess/201810/config" xmlns:v3="http://schemas.microsoft.com/AssignedAccess/2020/config" xmlns:v5="http://schemas.microsoft.com/AssignedAccess/2022/config"> <Profiles> <Profile Id="{9A2A490F-10F6-4764-974A-43B19E722C24}"> <AllAppsList> <AllowedApps> <App AppUserModelId="Microsoft.RemoteDesktop_10.2.3012.0_x64__8wekyb3d8bbwe" /> </AllowedApps> </AllAppsList> <v5:StartPins><![CDATA[{ "pinnedList":[ {"packagedAppId":"Microsoft.RemoteDesktop_10.2.3012.0_x64__8wekyb3d8bbwe"}, ] }]]></v5:StartPins> <Taskbar ShowTaskbar="true" /> </Profile> </Profiles> <Configs> <Config> <AutoLogonAccount rs5:DisplayName="RDUSER" /> <DefaultProfile Id="{9A2A490F-10F6-4764-974A-43B19E722C24}" /> </Config> </Configs> </AssignedAccessConfiguration> "@ $namespaceName="root\cimv2\mdm\dmmap" $className="MDM_AssignedAccess" $obj = Get-CimInstance -Namespace $namespaceName -ClassName $className $obj.Configuration = [System.Net.WebUtility]::HtmlEncode($assignedAccessConfiguration) Set-CimInstance -CimInstance $obj201Views0likes2CommentsDoes Microsoft stop support WMIC or WMI?
Hello everyone, Nice to meet you! I heard that MS has plans to deprecate and stop supporting the VB script very soon. I have few queries, please clarify Does Microsoft stop supporting WMIC or WMI along with the VB script? Can we use WMI commands in PowerShell scripts? thanks Madhu56Views0likes1CommentPowerShell data explanation and advice
Hi everyone. Not even sure how to ask and maybe it seems dramatic but I am reaching out for a little help here. Can someone help me understand this data I copied from PowerShell? I typed the same commands for user "smell" and user "Public". I have a node in network probably and I really hope for the worse to be honest. Reading about it got me pumped. Of course I have no idea if this could be the small window sun shines through or just another big nothing. Anyway, thanks to anyone who sets me straight about it. Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:\Users\smell> whoami / user ERROR: Invalid argument/option - '/'. Type "WHOAMI /?" for usage. PS C:\Users\smell> whoami /user USER INFORMATION ---------------- User Name SID =================== ============================================ thinkpadt16g2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> wmic useraccount where name='%username%' get domain,name,sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> wmic useraccount where name='%username%' get domain,name,sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> [Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object -Property @('Name', 'User') Name User ---- ---- THINKPADT16G2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> wmic useraccount where name='smell' get sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> wmic useraccount where sid='<sid>' get domain,name Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\smell> wmic useraccount where sid='S-1-5-21-2399413288-642862217-314349489-1001' get domain,name Unexpected switch at this level. PS C:\Users\smell> wmic useraccount get domain,name,sid Domain Name SID ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> Get-WmiObject win32_useraccount | Select domain,name,sid domain name sid ------ ---- --- ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> PS C:\Users\smell> Get-LocalUser | Select-Object -Property @('Name', 'SID') Name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> Get-CimInstance -query 'Select * from win32_useraccount' | ft name, SID name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\smell> [Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object -Property @('Name', 'User') Name User ---- ---- THINKPADT16G2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\smell> C:\Users\Public C:\Users\Public : The term 'C:\Users\Public' 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:1 + C:\Users\Public + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Public:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> C:\Users\Public> C:\Users\Public> : The term 'C:\Users\Public>' 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:2 + C:\Users\Public> + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Public>:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> C:\Users\ C:\Users\ : The term 'C:\Users\' 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:2 + C:\Users\ + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> C:\Users C:\Users : The term 'C:\Users' 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:2 + C:\Users + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\smell> PS C:\> Set-Location -PathC:\Users\Public Get-Process : A positional parameter cannot be found that accepts argument 'Set-Location'. At line:1 char:1 + PS C:\> Set-Location -PathC:\Users\Public + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-Process], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand PS C:\Users\smell> Set-Location -Path C:\Users\Public PS C:\Users\Public> whoami /user USER INFORMATION ---------------- User Name SID =================== ============================================ thinkpadt16g2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\Public> wmic useraccount where name='%username%' get domain,name,sid Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> [Security.Principal.WindowsIdentity]::GetCurrent() | Select-Object -Property @('Name', 'User') Name User ---- ---- THINKPADT16G2\smell S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\Public> [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value S-1-5-21-2399413288-642862217-314349489-1001 PS C:\Users\Public> wmic useraccount where name='username' get sid​ Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> wmic useraccount where name='smell' get sid​ Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> wmic useraccount where sid='<sid>' get domain,name Node - THINKPADT16G2 ERROR: Description = Invalid query PS C:\Users\Public> wmic useraccount where sid='S-1-5-21-2399413288-642862217-314349489-1001' get domain,name Unexpected switch at this level. PS C:\Users\Public> wmic useraccount get domain,name,sid Domain Name SID ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public> Get-WmiObject win32_useraccount | Select domain,name,sid domain name sid ------ ---- --- ThinkPadT16G2 Administrator S-1-5-21-2399413288-642862217-314349489-500 ThinkPadT16G2 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 ThinkPadT16G2 Guest S-1-5-21-2399413288-642862217-314349489-501 ThinkPadT16G2 smell S-1-5-21-2399413288-642862217-314349489-1001 ThinkPadT16G2 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public> Get-LocalUser | Select-Object -Property @('Name', 'SID') Name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public> Get-CimInstance -query 'Select * from win32_useraccount' | ft name, SID name SID ---- --- Administrator S-1-5-21-2399413288-642862217-314349489-500 DefaultAccount S-1-5-21-2399413288-642862217-314349489-503 Guest S-1-5-21-2399413288-642862217-314349489-501 smell S-1-5-21-2399413288-642862217-314349489-1001 WDAGUtilityAccount S-1-5-21-2399413288-642862217-314349489-504 PS C:\Users\Public>345Views0likes1CommentAutomatically Triggering the Smartcard PIN Prompt in Outlook
I use Outlook to receive encrypted emails that are protected by a certificate stored on my smartcard. When opening these emails, a Windows Security prompt appears, asking me to enter the PIN for my smartcard to decrypt the message. Once the PIN is entered, I can access the email contents. I'm looking for a way to automatically trigger the PIN entry dialog via code so that the user is prompted to enter the PIN without manually clicking on the encrypted email. The user will still need to insert their smartcard and manually enter the PIN, but I want the dialog itself to be initiated programmatically. I would prefer to implement this solution in PowerShell, an Outlook macro (VBA), or Delphi. However, I encountered an issue: when attempting to display the email using MailItem.Display(True), the PIN dialog does not appear. Instead, the following error message is shown: "The name of your digital ID could not be found by the underlying security system." Has anyone experienced this or have suggestions on how to automate the process while keeping the PIN entry manual and secure? Thank you in advance for your help!148Views0likes0CommentsPrinter Driver not found in DriverStore even though the file is there
I have a script that installs printer drivers onto a machine. It has worked perfectly for years up until yesterday. This is the script: # This script works on Windows 8 or newer since the add-printer cmdlets are't available on Windows 7. # Download the HP Univeral Printing PCL 6 driver. # To find\extract the .inf file, run 7-zip on the print driver .exe and go to the folder in Powershell and run this command: get-childitem *.inf* |copy-item -destination "C:\examplefolder" Otherwise it's hard to find the .inf files. $driversrc="\\10.1.1.21\sysprep\Printer Drivers\ApeosC2570\ffac7070pcl6220420w636iml\Software\PCL\amd64\Common\001\FFSOBPCLA.inf" Write-Host "Reading from here: $driversrc" $driver = "FF Apeos C2570 PCL 6" $address = "10.1.1.31" $portnamesuffix = "_1" $portname = "$address$portnamesuffix" $name = "Admin Apeos C2570" $sleep = "3" # The invoke command can be added to specify a remote computer by adding -computername. You would need to copy the .inf file to the remote computer first though. # This script has it configured to run on the local computer that needs the printer. # The pnputil command imports the .inf file into the Windows driverstore. # The .inf driver file has to be physically on the local or remote computer that the printer is being installed on. Invoke-Command {pnputil.exe -a $driversrc } Add-PrinterDriver -Name $driver Start-Sleep $sleep #Get the infos of all printer $Printers = Get-WmiObject -Class Win32_Printer $PrinterPorts = Get-PrinterPort $PrinterName = $name # This creates the TCP\IP printer port. It also will not use the annoying WSD port type that can cause problems. # WSD can be used by using a different command syntax though if needed. Try { Write-Verbose "Get the specified printer info." $Printer = $PrinterPorts | Where{$_.Name -eq "$portname"} If (! $Printer) { Write-Verbose "Adding printer port." Add-PrinterPort -Name $portname -PrinterHostAddress $address Write-Host "$portname has been successfully added." } Else { Write-Warning "Port already exists." } } Catch { $ErrorMsg = $_.Exception.Message Write-Host $ErrorMsg -BackgroundColor Red } start-sleep $sleep Try { Write-Verbose "Get the specified printer info." $Printer = $Printers | Where{$_.Name -eq "$PrinterName"} If (! $Printer) { Write-Verbose "Adding printer." Add-Printer -DriverName $driver -Name $name -PortName $portname Write-Host "$PrinterName has been successfully added." } Else { Write-Warning "$PrinterName is already installed!." } } Catch { $ErrorMsg = $_.Exception.Message Write-Host $ErrorMsg -BackgroundColor Red } Start-Sleep $sleep #Update the infos of all printer $Printers = Get-WmiObject -Class Win32_Printer Try { Write-Verbose "Get the specified printer info." $Printer = $Printers | Where{$_.Name -eq "$PrinterName"} If($Printer) { Write-Verbose "Setting the default printer." $Printer.SetDefaultPrinter() | Out-Null Write-Host "$PrinterName has been successfully set as the default printer." } Else { Write-Warning "Cannot find $PrinterName, can't set it as the default printer." } } Catch { $ErrorMsg = $_.Exception.Message Write-Host $ErrorMsg -BackgroundColor Red } Try { If($Printer) { Write-Verbose "Setting printer defaults." Set-PrintConfiguration -PrinterName $PrinterName -Color $false -DuplexingMode TwoSidedLongEdge | Out-Null Write-Host "$PrinterName has printing defaults set." } Else { Write-Warning "Cannot find the specified printer, can't set printer defaults." } } Catch { $ErrorMsg = $_.Exception.Message Write-Host $ErrorMsg -BackgroundColor Red } Get-PrintConfiguration -PrinterName $PrinterName # This prints a list of installed printers on the local computer. This proves the newly added printer works. Write-Warning "You must manually set the printer Output Color Preference to Black and White. Do it now!" get-printer |Out-Printer -Name $name Write-Host "If all went well a page should be printing out on the printer now." When I run the commands manually, the error persists. This is the error: Add-PrinterDriver : The specified driver does not exist in the driver store. dd-PrinterDriver -Name "[Name]" -InfPath "[Path]" PS C:\Windows\System32] At line:1 char:1 + Add-PrinterDriver -Name "[Name]" -InfPath "[Path]" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (MSFT_PrinterDriver:ROOT/StandardCimv2/MSFT_PrinterDriver) [Add-PrinterDri ver], CimException + FullyQualifiedErrorId : HRESULT 0x80070705,Add-PrinterDriver I want to know if there is a reason that the driver is not getting found in the DriverStore despite my being able to locate it. And whether others have this issue, it appears as if it's a windows issue.1KViews0likes9CommentsPowershell masking password
Hello Everyone, I have the script (API POST) below which is working fine. $UserPass = "username:password" [string]$stringToEncode=$UserPass $encodedString=[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($stringToEncode)) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("content-type", "application/json") $headers.Add("accept", "application/json") $headers.Add("Authorization", "Basic " + $encodedString) Invoke-RestMethod -Uri "https://api_base_url/session" -Headers $headers -Method POST I want to mask the password instead of plain text. So modified it to below which will ask to enter the masked password. $UserPass = "username:$(Read-Host -Prompt "Please type the password" -AsSecureString)" But the whole script is not working anymore. When I troubleshoot, there is a difference in encoding/decoding. I ran an online base64 decode and encode, the result is different. Plain text password - username:password dXNlcm5hbWU6cGFzc3dvcmQ= ---> username:password Masked password - username:$(Read-Host -Prompt "Please type the password" -AsSecureString) dXNlcm5hbWU6U3lzdGVtLlNlY3VyaXR5LlNlY3VyZVN0cmluZw== ---> username:System.Security.SecureString How can I mask the password but able to read the System.Security.SecureString as the actual password? Thank you in advanced.415Views0likes2CommentsPowershell Profiles
Hi! I would like to create profiles for powershell that on launch run commands like ssh to autoconnect to server. I tried making powershell profiles in window but besides of just existing it hasn't changed anything. When using command New-Item -Path $profile.CurrentUserCurrentHost -ItemType File -Force It is making profile used by whole powershell. How can i change that so profile for ex. HPServer launches different commands and RPIServer other?337Views0likes2Comments